Sebastian Braun created HTTPCLIENT-2220:
-------------------------------------------
Summary: file upload with MultipartEntityBuilder causes "socket
write error"
Key: HTTPCLIENT-2220
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2220
Project: HttpComponents HttpClient
Issue Type: Bug
Components: HttpClient (classic)
Affects Versions: 4.5.13, 4.5.2
Environment: server = Apache Server
Reporter: Sebastian Braun
Fix For: 4.5.13
I have some trouble, uploading a file with the MultipartEntityBuilder using the
Apache HTTP client 4.5.13.
It crashes with an {color:#de350b}"Software caused connection abort: socket
write error"{color} message.
This kind of behavior did not occur in older versions, so I traced it back back
to the rather ancient version 4.5.2.
4.5.2 -> aborts with an socket write error
4.5.1 -> works fine
It could be similar to this issue
https://issues.apache.org/jira/browse/HTTPCLIENT-1722.
This issue is closed and a duplicate of another issue. Unfortunately there no
reference to the original issue, which might contain additional information.
This is the source code:
try (CloseableHttpClient client = HttpClients.createDefault()) {
File file = new File("readyForUpload.tar");
HttpPost postRequest = new HttpPost("https://...");
// enable Expect: 100-continue, because the server
RequestConfig requestConfig =
RequestConfig.custom().setExpectContinueEnabled(true).build();
HttpEntity entity = MultipartEntityBuilder.create()
.addBinaryBody("UPLOAD_FILENAME", file,
ContentType.APPLICATION_OCTET_STREAM, file.getName())
.addTextBody("SOME_TEXT", "lorem ipsum ...")
.build();
postRequest.setConfig(requestConfig);
postRequest.setEntity(entity);
HttpResponse response = client.execute(postRequest);
HttpEntity responseEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (responseEntity != null) {
System.out.println(EntityUtils.toString(responseEntity));
EntityUtils.consume(responseEntity);
}
}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]