node.js - Converting cURL request for node js using Request -
I think this is a simple one: I want to make a request at a This is my valid curl command that returns a JavaScript object: After reading manual and request manual cURL, here I have tried in Your options are incorrect for one. In addition, by specifying function (error, response, body): Node.js As the server I am currently doing this with curl. Whatever I try, I get error 404 from the server.
curl - data "Ajax = 1 & amp;; Example = test" http: // Some -site-example.com
Node.js :
request.post ({'content-type': 'application / x-www-form-urlencoded', Ajax: '1', example: 'test', url: 'http: // some-site- Example.com}}, function (error, result, body) {if (error) console.log (err); else console.log (body);});
form , it automatically sets the correct
content-type . Then try it:
request.post ({form: {ajax: '1', example: 'test'}, url: 'http://some-site-example.com' }, Instead of {
request.post ({'content-type': 'application / x -www-form-urlencoded ', ajax:' 1 ', example:' test ', url:' http: //some-site-example.com '}, function (fault, result, body) {
< / Pre>
Comments
Post a Comment