[英]Netflix Feign Content type 'pplication/json;charset=UTF-8' not supported
I'm using Netflix Feign to make my java http clients, using a client like this: 我正在使用Netflix Feign来制作我的Java http客户端,使用这样的客户端:
public interface PromocodeClient {
@Headers({
"Content-Type:" + MediaType.APPLICATION_JSON_UTF8_VALUE, "userIdentifier: {userIdentifier}"
})
@RequestLine("POST /rootpath/{code}/unblock")
Boolean unblock(
@Param("userIdentifier") String userIdentifier,
@Param("code") String promocode,
BookingDTO booking);
static PromocodeClient connect() {
return Feign.builder()
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.target(PromocodeClient.class, Urls.SERVICE_URL.toString());
//Url.SERVICE_URL = http://localhost:8082/1.0
}
I'm getting an strange error 我收到一个奇怪的错误
{
"timestamp" : "2016-08-02T07:47:16.208+0000",
"status" : 415,
"error" : "Unsupported Media Type",
"exception" : "org.springframework.web.HttpMediaTypeNotSupportedException",
"message" : "Content type 'pplication/json;charset=UTF-8' not supported",
"path" : "/1.0/rootpath/COD_PROMOCODE/unblock"
}
}
The message says "Content type ' pplication /json;charset=UTF-8' not supported" but I'm using the MediaType.APPLICATION_JSON_UTF8_VALUE
of Spring which value is 该消息显示“内容类型' pplication / json; charset = UTF-8'不支持”,但我正在使用Spring的
MediaType.APPLICATION_JSON_UTF8_VALUE
,其值为
application/json;charset=UTF-8
application / json; charset = UTF-8
Anyone knows what is happening? 有人知道发生了什么吗?
You may need a space after the colon: 您可能需要在冒号后面加一个空格:
"Content-Type: " + MediaType.APPLICATION_JSON_UTF8_VALUE
^ here
It is not required by the HTTP standard : HTTP标准不需要它:
The field value MAY be preceded by any amount of [linear whitespace], though a single [space] is preferred.
字段值可以前面带有任意数量的[线性空格],尽管最好使用单个[空格]。
but it is possible that the server you are talking to isn't actually fully compliant with the HTTP standard, and so does something like: 但您正在与之交谈的服务器实际上可能并不完全符合HTTP标准,因此可能会发生以下情况:
header.substring(header.indexOf(':') + 2)
to find the value of the header, which handles the "preferred" case only. 查找标头的值,该标头仅处理“首选”情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.