使用stubrunner
运行客户端应用程序时出现以下错误$filePath = "/myfolder/const.json";
$const = file_get_contents($filePath."?k=".filemtime($filePath));
wiremock提供以下信息
Getting org.springframework.web.client.HttpClientErrorException: 404
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700)
我的合同看起来像这样
{
"url" : "/app/crm/customer/40",
"absoluteUrl" : "http://localhost:6565/app/crm/customer/40",
"method" : "GET",
"clientIp" : "127.0.0.1",
"headers" : {
"accept" : "text/plain, text/plain, application/json, application/json, application/*+json, application/*+json, */*, */*",
"domain" : "IND",
"host" : "localhost:6565",
"connection" : "Keep-Alive",
"user-agent" : "Apache-HttpClient/4.5.3 (Java/1.8.0_144)",
"accept-encoding" : "gzip,deflate"
},
"cookies" : { },
"browserProxyRequest" : false,
"loggedDate" : 1508757427831,
"bodyAsBase64" : "",
"body" : "",
"loggedDateString" : "2017-10-23T11:17:07Z"
}
Closest match:
{
"urlPattern" : "/app/crm/customer/[0-9]{2}",
"method" : "GET",
"headers" : {
"Content-Type" : {
"equalTo" : "application/json"
},
"domain" : {
"equalTo" : "IND"
}
}
}
我尝试通过更改内容类型和其他详细信息来解决问题。我在哪里做错了。感谢。
答案 0 :(得分:0)
它写的确切是问题所在。换句话说,答案就在你的问题中。
为了符合您的要求,它需要看起来像这样
{
"urlPattern" : "/app/crm/customer/[0-9]{2}",
"method" : "GET",
"headers" : {
"Content-Type" : {
"equalTo" : "application/json"
},
"domain" : {
"equalTo" : "IND"
}
}
}
这些是您传递的标题
"headers" : {
"accept" : "text/plain, text/plain, application/json, application/json, application/*+json, application/*+json, */*, */*",
"domain" : "IND",
"host" : "localhost:6565",
"connection" : "Keep-Alive",
"user-agent" : "Apache-HttpClient/4.5.3 (Java/1.8.0_144)",
"accept-encoding" : "gzip,deflate"
},
我没有看到Content-Type
等于application/json
标头。这就是请求不匹配的原因。