简体   繁体   English

Java中的MultipartEntityBuilder HttpPost套接字写入错误

[英]MultipartEntityBuilder HttpPost socket write error in java

I am trying file upload with httpPost request (by MultipartEntityBuilder) in java. 我正在尝试使用java中的httpPost请求(通过MultipartEntityBuilder)上传文件。 But i get a Software caused connection abort: socket write error . 但是我得到了软件导致的连接中断:套接字写入错误

Here is my httpPost body (in wireShark) 这是我的httpPost正文(在wireShark中)

------WebKitFormBoundaryWphJNFngxYSpEvNO
Content-Disposition: form-data; name="csrf_token"

csrf:sjwzV6dOZaNFwc0jWVrNNcFvhM7uv3BK00vZ0hCgEUzi2cG7r7Arx0Q3UZKlXeaR
------WebKitFormBoundaryWphJNFngxYSpEvNO
Content-Disposition: form-data; name="imagefilename"; filename="myfile.bin"
Content-Type: application/octet-stream

²qz‹ÁOOõMÓâg‘Ç`:----This area is file's binary code------Êëá‡/oåup

code side is: 代码方面是:

            File file = new File(filePath);
            String message = csrf_token;
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            builder.addBinaryBody("imagefilename", file, ContentType.DEFAULT_BINARY, file.getName());
            builder.addTextBody("csrf_token", message, ContentType.DEFAULT_BINARY);
//
            HttpEntity entity = builder.build();
            httpPost.setEntity(entity);
            HttpResponse response = httpClient.execute(httpPost);

and error: 和错误:

在此处输入图片说明

Is there any idea? 有什么主意吗 thanks for all. 谢谢大家

i resolved the problem, thesee links are useful for answer 我解决了问题,thesee链接对于回答很有用

here is fileupload with http Client example 是http客户端示例的文件上传

here is fileupload too, with httpUrlConnection 也是通过httpUrlConnection进行的文件上传

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM