我已经有效地使用了 wiremock 一段时间了,我想启用对模拟 API 的 CORS 访问。
我试过在响应头中设置 Access-Control-Allow-Origin: * 和其他头,但都无济于事。
这是我拥有的映射示例:
{
"request": {
"method": "POST",
"urlPattern": "/api/v2/general/login[\\/\\&\\?]*",
"bodyPatterns": [{
"equalToJson": "{\"password\":\"password\",\"username\":\"john@cougar.com\"} ",
"jsonCompareMode": "LENIENT",
"ignoreArrayOrder" : true,
"ignoreExtraElements" : true
}]
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json",
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods" : "*",
"Access-Control-Allow-Headers": "Accept, Content-Type, Content-Encoding, Server, Transfer-Encoding",
"X-Content-Type-Options" : "nosniff",
"x-frame-options" : "DENY",
"x-xss-protection" : "1; mode=block"
},
"bodyFileName": "/login_response_johncougar.json"
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么导致 CORS 不起作用?
提前致谢。
我需要使用wiremock 来测试发送数据的POST 请求,如下所示:
{
"name": "known fixed value",
"dateOfBirth": 5123456789000,
"email": "known fixed value",
"currentDate": any numeric value,
"status": any text value with alphabets, numbers and symbols
}
Run Code Online (Sandbox Code Playgroud)
前 3 个字段(姓名、出生日期和电子邮件)是固定的已知值,不会从一个请求到下一个请求而改变。
最后 2 个字段(currentDate 和 status)从一个请求到下一个请求随机变化,但它们是强制字段,可以保存任何值。
我如何设计一个测试这个的映射?
提前致谢。