这个API工作正常;我可以看到它到达服务器并返回200。但是客户机代码中捕获的响应为空。我已经通过邮差检查了回复,我可以看到状态码。不确定为什么客户端无法解码响应
@Bean
fun buildClient(
objectMapper: ObjectMapper,
@Value("${cbase-uri}") url: String
): Client {
return FeignApiBuilder.builder(Client::class.java, url) { it }
.build()
}
API接口
@Headers(
"Accept: ${MimeTypeUtils.APPLICATION_JSON_VALUE}",
"Content-Type: ${MimeTypeUtils.APPLICATION_JSON_VALUE}"
)
interface Client {
@RequestLine("POST /v1/test")
fun submit(
request: body
): ResponseEntity<Unit>
}
实施override fun test(request: body) {
try {
val response = client.submit(request)
if (response.statusCodeValue == 200) {
logger.info("Success")
return
} else {
throw Exception("Internal Server Error")
}
} catch (e: Exception) {
throw Exception("Exception occurred while calling submit api", e)
}
}
看起来问题是由于API接口方法的返回类型。您正在返回"ResponseEntity",您能否将返回类型更改为期望的类型并检查是否解决问题