I’m trying print the request body at “Test Results” :
My Params and Test Results:
But name=bbb&password=456
is not my truly request body.
How to only print name=aaa&password=123
?
Thanks!
I’m trying print the request body at “Test Results” :
My Params and Test Results:
But name=bbb&password=456
is not my truly request body.
How to only print name=aaa&password=123
?
Thanks!
Hey @aisen0921
Welcome to the community
I’m unsure what you’re asking, would you be able to expand on the information in the question, please?
What are you trying to Test? What is the expected outcome?
If you wanted to check the params for the request, you would probably need to access those via pm.request.url.query
.
I update my question for more information.
My url like http://url/login.json ,and every url is endwith “.json”
I use pm.request.url.query
print empty.
My bad - I think I actually read your question incorrectly.
I’m still not really sure what you’re trying to do - Do you need a check in place to test for something? Currently, that’s not testing anything.
pm.request.body.urlencoded
would be what you need to see those values but this is just going to show you the same thing.
This is not what is actually sent in the request though.
If you use the Postman Console to log that output
console.log(pm.request.body.urlencoded)
You will see that the disabled key/value pairs have the disabled
key within the object. Postman uses this during the request to know not to send them through.
You can see the response body
in the image that the hidden key/value pairs were not sent as part of the actual request.
If you see here, I’m passing “test1” and “test2”, I’ve unchecked “test3”:
As Danny said, if a parameter is unchecked it’ll have this “disabled: true” key/value.
If I console log “pm.request.body.urlencoded”, it’ll return an array of objects.
So I’m doing a filter on all the parameters to only show me ones that DON’T have “disabled: true”
I’m console logging this:
And here’s the valid params used as test name (Not sure what your use case for needing this but shrugs:
This would also add those non hidden values to the Test
name but obviously as an object
pm.test(JSON.stringify(pm.request.body.urlencoded.toObject(true)))
@danny-dainton
That’s OK.
I use “pm.test” because I want see request body、content-type、response content in Run Results, or there has another way ?
(“Export Results” has too many detail for me.)
My requirement like this picture, it’s looks brief, can see all the necessary conditions and responses.
Thank you for providing “console.log” this method,I will use it.
@postman-paul540
.filter is what I need, and the example is clearly, thanks.
You’re able to view the details of each of the requests, from the Collection Runner, by selecting the requests name:
This seems like the information that you want to see.
More information about this can be found here:
https://learning.getpostman.com/docs/postman/collection_runs/debugging_a_collection_run
JSONError: Unexpected token ‘a’ at 1:1
im facing this error ^ for below script, can some one help please
var jsonReq = JSON.parse(pm.request.body);
var jsonRes = pm.response.json();
console.log("Request body is as below: ");
console.log(jsonReq);
console.log("Response body is as below: ");
console.log(jsonRes);
What’s the response from that request?
Feeling like it’s trying to parse something that isn’t JSON.
var jsonReq = JSON.parse(pm.request.body);
this is failing^
Request body is in urlencoded
i tried doing
var jsonReq = JSON.parse(pm.request.body.urlencoded);
var jsonRes = pm.response.json();
console.log("Request body is as below: ")
console.log(jsonReq)
console.log("Response body is as below: ")
console.log(jsonRes)
im getting JSONError: Unexpected token ‘a’ at 1:1
I’m not sure why you’re doing a JSON.parse()
on pm.request.body.urlencoded
var jsonReq = pm.request.body.urlencoded;
var jsonRes = pm.response.json();
console.log("Request body is as below: ")
console.log(jsonReq)
console.log("Response body is as below: ")
console.log(jsonRes)
I thought JSON.parse can convert to JSON format and show in console
in my case i used formdata
this is how i got my body.formdata.json
let body = Object.values(pm.request.body.formdata)
let values = JSON.parse(body[1])