Content-Type Override
See original GitHub issueFrom this bit of code in _putorPost() function in oauth.js (line 496)
if ( typeof post_body != "string" && !Buffer.isBuffer(post_body) ) { post_content_type= "application/x-www-form-urlencoded" extra_params= post_body; post_body= null; }
With the new Twitter DM API I need to be able to set the Content Type to JSON when the post-body is JSON https://dev.twitter.com/rest/reference/post/direct_messages/events/new
So currently my post function looks like this : oauth.post( ‘https://api.twitter.com//1.1/direct_messages/events/new.json’, access_token, access_token_secret, {“event”: {“type”: “message_create”, “message_create”: {“target”: {“recipient_id”: “4534871”}, “message_data”: {“text”: “Hello World!”}}}}, “application/json”, function(e, data ) { } );
But as post-content-type gets overridden to “application/x-www-form-urlencoded”, I get an error. Could this please be updated so you can specify the content type?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:5
A minimal change (which I think is less obvious/explicit and thus don’t like as well) is to change
_performSecureRequest
to move theheaders["Content-Type"]= post_content_type;
line aboveThat way if you include ‘Content-Type’ in the
customHeaders
object passed to the OAuth constructor. I don’t love this though due to the obvious/explicit problem I mentioned above and because it forces you to pass all of the parameters beforecustomHeaders
when you want to change the content-type.+1