-3

I am trying to post json data to a url that is executed as shown below in cURL Facebook request format

The snapshot below is my code using the request module in Node.js that works perfectly Request mode code works perfectly I am trying to covert the above code written using the request module into unirest and it gives a status 400 every time. Unirest code gives status 400

Am I missing something here? Appreciate the help in advance

PirateApp
  • 5,433
  • 4
  • 57
  • 90

2 Answers2

0

I have fixed the error. The key I was sending in unirest json:messageData was incorect. For more details, the answer is here on GitHub issues

PirateApp
  • 5,433
  • 4
  • 57
  • 90
0

Thanks, for the answer. It's so many util to me. Im my case, the application use our proxy application and the request was working without this proxy, but with proxy the the response arrive with 400 code.

Case: I need send a request with content-length: 0

What i was make: What ocurred was that the request send with header content-length: 0, and i have's set this headers, but too sended a empty body in .send() method.

Solution: Created a unirest request, without .send(), because the content is empty, it's working to me.

// the wrong code:
let req = unirest
     .post(url)
     .proxy(myProxy) 
     .headers(myHeaders)
     .send({})
...
req.end(funcCallback)
// the correct code:
unirest
     .post(url)
     .proxy(myProxy) 
     .headers(myHeaders)
...
req.end(funcCallback);