![](/img/trans.png)
[英]I check API endpoints using POSTMAN. But its post HTTP method is not working properly
[英]How to check the content of a POST method in Postman?
我正在测试一个在触发器后将在服务器中创建POST
方法的API
,并且我想保证请求正文具有所有必填字段。
我还找不到正确的解决方案,即如何指向请求正文。
如果有一种方法可以检查请求是否为有效的Json,然后检查Json的每个字段(名称,性别等),那将是很好的。
请求正文:
{
"requestId": "ok01",
"parentRequestId": "some text",
"formType": "some text",
"sourceURL": "some text",
"documentType": "some text",
"documentNumber": "some text",
"phoneType": "some text",
"phoneArea": "some text",
"phoneNumber": "some text",
"name": "some text",
"customerId": "some text",
"email": "some text",
"locationName": "some text",
"currentAddress": "some text",
"newAddress": "some text",
"descriptions": "some text",
"creationDate": "some text",
"geoLocation": "some text",
"ipsourceFibertel": "some text",
"userId": "some text",
"retries": "some text",
"productList": [
{
"products": "some text"
},
{
"products": "some text"
}
]
}
响应主体:
{
"OK"
}
// I tried like this, but it didnt work
pm.test("Check field 'requestId'", function () {
pm.requestBody.have.jsonBody("requestId");
});
不确定总体目标是什么,但是如果您想检查Request Body
是否使用了requestId
属性,则可以执行以下操作:
pm.test("Check the request data", function () {
pm.expect(JSON.parse(pm.request.body.raw)).to.have.property('requestId');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.