小编Mau*_*ves的帖子

okhttp3 - 413 请求实体太大

当我的系统使用 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();
    }
}
Run Code Online (Sandbox Code Playgroud)

java request okhttp http-status-code-413

2
推荐指数
1
解决办法
7560
查看次数

标签 统计

http-status-code-413 ×1

java ×1

okhttp ×1

request ×1