此API工作正常;我可以看到它命中服务器并返回200。但在客户端代码中捕获的响应为空。我已经通过 Postman 检查了响应,我可以看到状态代码。不确定为什么客户端无法解码响应
@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)
}
}
1条答案
按热度按时间42fyovps1#
看起来问题是由于API接口方法的返回类型。您正在返回“ResponseEntity”,您可以将返回类型更改为预期类型并检查是否修复了问题