美文网首页
java.net.ProtocolException: expe

java.net.ProtocolException: expe

作者: Neuropathy_e711 | 来源:发表于2020-04-26 14:39 被阅读0次

okhttp上传文件报错,上传文件大小跟接受文件大小不一致。

关闭文件读写流。

文件名称过长!改短就行。

附上传文件代码:


public class ClientUploadUtils {
   public static ResponseBody upload(String url, File file,String num) throws Exception {
        OkHttpClient client = new OkHttpClient();
        RequestBody requestBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("logFile", file.getName(),
                        RequestBody.create(MediaType.parse("multipart/form-data"), file))
                .addFormDataPart("serial_no",num)
                .build();

        Request request = new Request.Builder()
                .header("Authorization", "Client-ID " + UUID.randomUUID())
                .url(url)
                .post(requestBody)
                .build();

        Response response = client.newCall(request).execute();
        if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);else Log.i("logCatch","upload Success");

        return response.body();
    }
}


相关文章

网友评论

      本文标题:java.net.ProtocolException: expe

      本文链接:https://www.haomeiwen.com/subject/wsodwhtx.html