簡體   English   中英

如何檢查Postman中POST方法的內容?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM