我在./mappings/*.json文件中描述了一个存根。
"request": {
"method": "POST",
"url": "/some/thing",
"bodyPatterns" : [ {
"matchesXPath" : {
"expression": "//nodeA/text()",
"contains": "999"
}
} ]
}
Wiremock(版本2.26.2)在独立模式下启动。当我这样调用服务时:
curl -d "<request><nodeA>999</nodeA></request>" -X POST http://localhost:8888/some/thing
我正在按预期从存根获得响应。问题在于该请求必须使用XML声明标签发送,例如
curl -d "<?xml version="1.0" encoding="UTF-8"?><request><nodeA>999</nodeA></request>" -X POST http://localhost:8888/some/thing
并且在这种情况下,请求不匹配。我试图在文档中找到关于它的信息,但到目前为止还没有运气
我发现问题出在我使用的curl
上。由于我在XML声明中使用了相同的双引号,因此它的格式不正确。现在我从文件加载请求主体,一切正常curl -H "Content-Type: application/xml" -d "@path_to_request_file" -X POST http://localhost:8888/some/thing