简体   繁体   中英

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:

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

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 :

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:

header.substring(header.indexOf(':') + 2)

to find the value of the header, which handles the "preferred" case only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM