当我的系统使用 okhttp3 发送 http 请求时,会出现以下问题:413 Request Entity Too Large
我想知道如何在 okhttp3 请求中设置最大大小,或者是否有针对此问题的其他解决方案。
public static String post(String url, String json) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.readTimeout(1, TimeUnit.MINUTES)
.build();
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.header("Authorization", authKey)
.url(url)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
if(response.code() != 200) {
return "request error";
}
return response.body().string();
}
}