简体   繁体   中英

Using postman to test POST request, how do I access the form-data inside the request?

I've been googling for a few hours, and I need help. I dont think I'm using the correct words. Anyhow, I'm using Claudia.JS to set up a POST request to my AWS Lambda function. Here's the basics of the function:

api.post('/leads', function (request) {
   console.log(request);
   return request;
});

When I use postman to test the post request, I'm returned the request object. Awesome. Then I try to pass form-data through. I set the key to 'username' and the value to 'this is the username'. This is what request.body is:

"body": "---------------------------
-019178618034620042564575\r\nContent-Disposition: form-data; 
name=\"username\"\r\n\r\nthis is the username\r\n----------------------
------019178618034620042564575--\r\n",`

I thought I could return request.body.username... to key the value of username...but I'm missing something.

How do I access the form data in the request?

update: okay. The website is taking the form data, making a post request...this function is receiving the post request? still-- in postman...if I were to put my own JSON in...why can I not access request.body like... request.body.username?

You should try console.log(request.data) to see your request object, ie. in my own case I can see the content of my request's body.

Have a look at https://www.getpostman.com/docs/postman/scripts/postman_sandbox to see all the relevant information about your request.

I solved this by looking at the header set in postman. It was set to form-data instead of application/JSON. All gravy now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM