I am using the example given here: https://github.com/expressjs/multer. However instead of using the form in the example, I am using Postman to POST some data, however I am getting an empty body. I have set Postman to use form-data. Any ideas what the problem could be?
Thanks
Related
I need to make a post using nodejs. I will send a text and a json file content to a url. Using insomia I can send normally (print below), but not in the code integration. Does anyone have an example?
SEND OK
ERROR
While calling Node API get HTTP method data comes in truncated format, incomplete JSON.
But when calling the same api using POSTMAN getting proper response.
If is there any issue regarding NodeAPI please guide how can I solve it?
I am writing node.js App. I am able to get data entered from postman via "x-www-form-urlencoded". But When I enter data with "form-data",the data is not accepted in API.I have tried with app.use(bodyParser.urlencoded({extended:false})) and app.use(bodyParser.urlencoded({extended:true})) . But still it is not working. Is there any way I can accept data via "form-data"?
As suggested in post you cannot use body-parser for form-data.
Instead, you can use a module like multer.
i' m a bit new to Node, so question may be stupid...
I am sending a POST request to a website (through http.request) and I want to be able to use the invisible POST data I get along the response.
I hope this is achievable, and I think so since I am able to preview those data in Chrome debugger.
PS : I understand that we can use BodyParser to parse and get those while listening for a POST call server side, but I have found no example of how to use it coupled with an http.request.
Thanks !
If the body of the HTTP response contains JSON, then you need to parse it first in order to turn it from a string into a JavaScript object, like this:
var obj = JSON.parse(body);
console.log(obj.response.auth_token);
More info on various ways of sending a POST request to a server can be found here: How to make an HTTP POST request in node.js?
Edit : So we figured it out in the comments. The value I needed was in the form to begin with, as a hidden field. My error was to think it was generated afterward. So I'll just grab it first then login, so I can use it again for future POST requests on the website.
I am sending a JSON object from web client, which looks like this:
{"AudioEncoder":{"Settings":{"1":{"audio_bitrate":"16000"}}}}
And in the request I get from req.body.myvalue:
{"AudioEncoder":{"Settings":[null,{"audio_bitrate":"16000"}]}}
In the Network panel of my browser I see correct value though:
myvalue[AudioEncoder][Settings][1][audio_bitrate]:16000
Error is where I am expecting object with key {1:... but get [null:....
Any ideas why would this happen?
I suspect your browser isn't actually sending JSON, it's sending application/x-www-form-urlencoded. This is not the correct value if you are trying to have the browser send JSON: myvalue[AudioEncoder][Settings][1][audio_bitrate]:16000. That's not JSON. Check the request headers for Content-Type and look at the raw body of the request to verify this. If you post your browser JS that's sending the AJAX, we can help you fix that. jQuery makes it a little tricky to specify the options correctly to get it to really send JSON.