Retrofit2/OkHttp3: REST Web 服务未指定字符集

Retrofit2/OkHttp3: REST webservice does not specify characterset

我访问的 Web 服务无法为我使用的内容指定内容类型或字符集。

有没有办法使用 retrofit2(或 okhttp3 客户端拦截器)添加相关信息,以便正确处理接收到的内容?

通过 Retrofit,您可以使用 @Headers 注释:

例如: @Headers("Cache-Control: max-age=640000")

然后您可以(如果您始终知道内容类型)将您的界面设置为:

@Headers("Content-Type: application/json")
@GET("widget/list")
Call<List<Widget>> widgetList();

https://square.github.io/retrofit/