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

Can't set "Content-Type" #75

Closed
AndersGerner opened this issue Feb 26, 2018 · 8 comments
Closed

Can't set "Content-Type" #75

AndersGerner opened this issue Feb 26, 2018 · 8 comments

Comments

@AndersGerner
Copy link

When trying to set request to have Content-Type header, then it writes the header as 'Content-type' so the server doesn't parse it, because it's written in quotes ' '.

Anybody got an idea on how I can set the header to have content-type: application/json ?

Thanks in advance

@SamDecrock
Copy link
Owner

I don't think that's possible. Are your sure?

@AndersGerner
Copy link
Author

Thanks for quick response @SamDecrock :)

For Sharepoint REST API, I need to set the Accept and Content-Type headers to application/json.
Otherwise it returns the response in XML.

But it doesn't seem to be working :(

Wouldn't I just update the request object in the options like this?

const options = {
  url: 'MySharepointSite,
  username: 'USERNAME',
  password: '********',
  workstation: '',
  domain: '',
  request: {
	'Accept': 'application/json;odata=verbose',
        'Content-Type': 'application/json',
  },
};

@SamDecrock
Copy link
Owner

SamDecrock commented Feb 27, 2018

There is no object called request in my library ;-)

I think this should work:

const options = {
  url: 'MySharepointSite',
  username: 'USERNAME',
  password: '********',
  workstation: '',
  domain: '',
  headers: {
	'Accept': 'application/json;odata=verbose',
        'Content-Type': 'application/json',
  },
};

@bradwallen
Copy link

I'm actually seeing the same thing as the OP. I sent my Content-Type as application/x-www-form-urlencoded and this is what I get in the log:
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Connection: 'keep-alive',
Note how Content-Type is enclosed in single quotes...

Here's the line of code:
headers: { 'Content-Type': "application/x-www-form-urlencoded", "Connection": "keep-alive",

@naavis
Copy link

naavis commented Mar 4, 2021

I'm having a similar problem with setting the User-Agent header in the requests. The server I am connecting to allows me to use NTLM authentication only if User-Agent is set to a specific value.

I can see from httpntlm.js that is is explicitely not using headers passed in via the options: type1options = _.extend({}, _.omit(httpreqOptions, 'headers', 'body'), type1options);

@SamDecrock
Copy link
Owner

Indeed, I will add the option to set custom headers back in. But first I need to write some extra tests to make sure I don't break anything.

@SamDecrock
Copy link
Owner

I added the option to pass in custom headers, see https://github.com/SamDecrock/node-http-ntlm#pass-in-custom-headers for an example. This is available from version 1.8.10

@creage
Copy link

creage commented Apr 13, 2023

@SamDecrock This commit f2c71c9 breaks authorization when used with headers option.
Basically, v1.8.9 works, v1.8.10 fails.

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

5 participants