我有一个集成测试,我将 mockserver-netty (v5.3.0) 与 springboot 2.0 应用程序一起使用。一切正常,但如果我尝试添加 Content-Type 标头,我会收到以下异常:
java.lang.IllegalArgumentException: Exception while parsing [{
"httpRequest" : {
"method" : "POST",
"body" : {
"type" : "XML",
"xml" : "......"
},
"times" : {
"remainingTimes" : 0,
"unlimited" : true
},
"timeToLive" : {
"unlimited" : true
}
}] for Expectation
at org.mockserver.client.AbstractClient.sendRequest(AbstractClient.java:95)
at org.mockserver.client.AbstractClient.sendExpectation(AbstractClient.java:441)
at org.mockserver.client.ForwardChainExpectation.respond(ForwardChainExpectation.java:25)
期望如下:
{
"method" : "POST",
"body" : {
"type" : "XML",
"xml" : "......"
}
},
"httpResponse" : {
"statusCode" : 200,
"headers" : {
"Content-Type" : [ "text/xml" ]
},
"body" : "......."
},
"times" : {
"remainingTimes" : 0,
"unlimited" : true
},
"timeToLive" : {
"unlimited" : true
}
}
我使用以下代码创建它:
private static HttpResponse responseWithBody(String responseBody, int statusCode, String contentType) {
return HttpResponse.response()
.withStatusCode(statusCode)
.withHeader("Content-Type",contentType)
.withBody(responseBody);
}
如果我只是用 .withHeader("Content-Type",contentType) 语句注释该行,那么一切运行正常。有什么线索吗?非常感谢