我必须使用非常旧的ktor版本(1.2.6)-请不要告诉我升级,我现在不能这样做。我试图发送一个后请求到另一个服务,我嘲笑测试与wiremock。
这是我的客户端配置:
object HTTP {
val client = HttpClient(Apache) {
followRedirects = false
engine {
customizeClient {
setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
}
}
install(JsonFeature) {
serializer = JacksonSerializer()
}
}
}
这段代码实际上是尝试执行post:
val url = "http://localhost:9099/v0/test"
val response = HTTP.client.post<TestResponse>(url) {
header(HttpHeaders.ContentType, "application/json")
contentType(ContentType.Application.Json)
body = TestRequest()
}
这是我的无线电配置:
WireMock.stubFor(
WireMock.post(WireMock.urlMatching("/v0/test"))
.willReturn(
WireMock.aResponse().withStatus(200)
.withBody(jacksonObjectMapper().writeValueAsString(testResponse))
)
)
当我用curl点击这个wiremock时,它工作正常,但是用上面的代码调用它会导致:
No transformation found: class kotlinx.coroutines.io.ByteBufferChannel -> class com.test.TestResponse
io.ktor.client.call.NoTransformationFoundException: No transformation found: class kotlinx.coroutines.io.ByteBufferChannel -> class com.test.TestResponse
at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:88)
有人能帮帮忙吗?
1条答案
按热度按时间bkkx9g8r1#
要解决您的问题,请将
Content-Type: application/json
标头添加到响应中: