在 API POST 请求的响应中,位置在 header 中作为键和值从两部分构建返回:URL 路径 + 唯一 ID
我只想在 Postman 测试中验证值的 URL 路径,因为在每次新请求后唯一 ID 都会不同。
响应中位置 header 值的示例:
api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses/5637454148
我只想验证:
api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses/
到目前为止我有:
pm.response.to.have.header("Location");
pm.response.to.be.header("Location", "api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/E000088/emailaddresses");
但这不是100%正确
最佳答案
如果您只想检查 header 是否包含字符串的一部分,您可以使用如下内容:
pm.test("Location Header", () => {
pm.response.to.have.header("Location");
pm.expect(pm.response.headers.get("Location")).to.include("api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses")
})
我不知道您的 URL 路径中的 guid
和 id
是否会更改,所以这是非常硬编码的,而不是动态的。
关于validation - 在 Postman 测试中使用哪个片段来验证 header 值的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59388702/