1

我想验证我的 web 服务的响应是有效的 xml。我知道可以使用以下代码段简单地为 json 响应完成:

    pm.response.to.be.json;

XML 呢?

pm.test("The body of the response is a valid XML", function () {
    pm.response.to.be.withBody;
    pm.response.to.be.xml; // ❓
});
4

1 回答 1

4

方法有很多种,这里是其中一种。

使用内置函数将 XML 正文转换为 JSON 对象xml2Json。如果函数返回值,则响应有效,否则无效。

pm.test("The body of the response is a valid XML", function () {
     pm.expect(xml2Json(responseBody)).to.exist;
});
于 2019-09-11T17:05:10.050 回答