mattr
mattr

Reputation: 87

How to set Content-Type header in Coffeescript POST request

I am trying to send a POST request to a Jenkins remote access api, and need to set the Content-Type header to 'application/xml' for the request to work.
I have tried setting it with .headers(Authentication: auth, Content-Type: 'application/xml') to no avail. The request doesn't even go through when I pass in the Content-Type argument. If I submit the request without the Content-Type argument, the html that comes back includes <h1>Error</h1>No Content-Type header.

This is the code I'm attempting to run:

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

Upvotes: 1

Views: 2550

Answers (1)

mattr
mattr

Reputation: 87

The problem was solved by adding quotes around the Content-Type field in the call to headers.

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

Upvotes: 2

Related Questions