Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with setting Content-Type #1311

Closed
domwoe opened this issue Dec 10, 2014 · 5 comments
Closed

Problem with setting Content-Type #1311

domwoe opened this issue Dec 10, 2014 · 5 comments

Comments

@domwoe
Copy link

domwoe commented Dec 10, 2014

var options = {
    proxy: process.env.QUOTAGUARDSTATIC_URL
    strictSSL: false, // allow us to use our self-signed cert for testing
    rejectUnhauthorized : false,
    headers: {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36',
        'Authorization':    'Basic '+authToken,
        'Accept-Encoding':  'application/json',
        'Content-Type':     'application/json'
    }
};

I set also options.form to be an object with my payload and use the request.post method.

But this is what I get as a response (deleted the private parts):
{"statusCode":415,"body":"","headers":{"date":"Wed, 10 Dec 2014 13:33:19 GMT","content-length":"0","connection":"close","content-type":"text/plain; charset=UTF-8","content-language":"en"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"","port":443,"hostname":"","hash":null,"search":null,"query":null,"pathname":"","path":"","href":""},"method":"POST","headers":{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36","Authorization":"","Accept-Encoding":"application/json","_Content-Type":"application/x-www-form-urlencoded_","content-length":41}}}

So it seems that the Content-Type is not set to application/json and this is why I get a 415.
What is the problem here?

@simov
Copy link
Member

simov commented Dec 10, 2014

When you are using the form key the content-type is always set to application/x-www-form-urlencoded. Which version of request do you use?

@domwoe
Copy link
Author

domwoe commented Dec 10, 2014

2.50.0

Aha, so how can I then post json?

@simov
Copy link
Member

simov commented Dec 10, 2014

Send it via json:{object} or body:{obj}, json:true, see the docs for more detailed information about the available options.

Your problem might be related to this bug as well #1310, so in any case try your tests with v2.49.0 as well.

@simov
Copy link
Member

simov commented Dec 10, 2014

@domwoe 2.51.0 is out, let us know what's the status with your issue.

@domwoe
Copy link
Author

domwoe commented Dec 11, 2014

2.51.0 works for me, while 2.50.0 didn't. Thanks.

@simov simov closed this as completed Dec 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants