简体   繁体   中英

Made sure content-type and content-encoding, still get 415 Unsupported media type

In my application, I am sending request with okhttp3 and retrofit2 . Here is I logged the request by HttpLoggingInterceptor :

  okhttp3.OkHttpClient: --> POST https://something/here http/1.1
  okhttp3.OkHttpClient: Content-Type: application/json; charset=UTF-8
  okhttp3.OkHttpClient: Content-Length: 2596
  okhttp3.OkHttpClient: --> END POST (2596-byte body)

And I have this in my server:

@Consumes("application/json; charset=UTF-8")

Currently, Keep getting HTTP 415 error code.

Environment:

  • RedHat
  • Retrofit:2.3.0
  • Okhttp:3.8
  • Logging-interceptor:3.8

Not only the @Produce type should match the @Consumes type, but also the @Body should be completely matched.

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