简体   繁体   中英

MultipartEntityBuilder HttpPost socket write error in java

I am trying file upload with httpPost request (by MultipartEntityBuilder) in java. But i get a Software caused connection abort: socket write error .

Here is my httpPost body (in 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

here is fileupload with http Client example

here is fileupload too, with httpUrlConnection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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