關於OkHttp設定Content-Type問題
阿新 • • 發佈:2019-01-30
通過建立Request.Builder物件,例項化post請求物件的時候重寫contentType方法設定型別。
Request.Builder builder = chain.request()
.newBuilder();
builder.post(new RequestBody() {
@Overridepublic MediaType contentType()
{
return MediaType.parse("application/json");
}
@Override
public void writeTo(BufferedSink sink) throws IOException
{
}
});
Request request = builder.build();