hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Dudgeon <tdudgeon...@gmail.com>
Subject Problem with InputStreamEntity
Date Wed, 05 Aug 2015 11:15:43 GMT
I'm having a strange problem with using InputStreamEntity for a POST 
If I use a StringEntity the operation works fine.
If I use an InputStreamEntity based on the same content then no content 
gets POSTed.
Any ideas why?

Example would be like this:

String source = "hello";
InputStream content = new ByteArrayInputStream(source.getBytes());

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(uri);

httpPost.setEntity(new StringEntity(source)); // this works
//httpPost.setEntity(new InputStreamEntity(content)); // this doesn't

try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
             System.out.println(response.getStatusLine().toString()); // 
gives a 200 either way
             HttpEntity entity = response.getEntity();
             String result = EntityUtils.toString(entity);
             System.out.println("Result: " + result);

To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org

View raw message