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 Node.js As the server I am currently doing this with curl. Whatever I try, I get error 404 from the server.
This is my valid curl command that returns a JavaScript object:
curl - data "Ajax = 1 & amp;; Example = test" http: // Some -site-example.com After reading manual and request manual cURL, here I have tried in 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);});
Your options are incorrect for one. In addition, by specifying 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 { function (error, response, body):
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