【问题标题】:How to set Content-Type header in Coffeescript POST request如何在 Coffeescript POST 请求中设置 Content-Type 标头
【发布时间】:2014-05-23 13:09:15
【问题描述】:

我正在尝试向 Jenkins 远程访问 api 发送 POST 请求,并且需要将 Content-Type 标头设置为 'application/xml' 以使请求正常工作。
我试过用.headers(Authentication: auth, Content-Type: 'application/xml') 设置它无济于事。当我传入 Content-Type 参数时,请求甚至没有通过。如果我在没有Content-Type 参数的情况下提交请求,则返回的html 包括<h1>Error</h1>No Content-Type header

这是我尝试运行的代码:

msg.http(url)
  .headers(Authorization: auth, Content-Type: 'application/xml')
  .query(name: name)
  .post(config_xml) (err, res, body) ->
    msg.send "POSTed"

【问题讨论】:

标签: html coffeescript httprequest


【解决方案1】:

通过在对标头的调用中的 Content-Type 字段周围添加引号解决了该问题。

.headers(Authorization: auth, 'Content-Type': 'application/xml')

【讨论】:

    猜你喜欢
    • 2012-05-27
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多