Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:49:03+00:00 2026-06-08T20:49:03+00:00

I am trying to POST some data taken from an InputStream. I was hoping

  • 0

I am trying to POST some data taken from an InputStream. I was hoping to avoid having to gather all the data into a byte array first, and instead stream the data, to save memory (I am POSTing data of about 10MB).

If I run the following:

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(target_url);
MultipartEntity entity = new MultipartEntity();
entity.addPart("data", new InputStreamBody(new ByteArrayInputStream(new byte[1]), 
    filename));
httpPost.setEntity(entity);
httpclient.execute(httpPost);

then I get:

org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:95)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:712)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:517)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
    [my code starts here]

However, if I change one line above, replacing the InputStreamBody with the equivalent ByteArrayBody, then all is well:

entity.addPart("data", new ByteArrayBody(new byte[1], filename));

What am I doing wrong?

(and would InputStreamBody actually stream the data, or am I wasting my time?)

I am using HttpClient-4.2.1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:49:05+00:00Added an answer on June 8, 2026 at 8:49 pm

    There is nothing wrong with what you are doing. The issue is likely to be that when using ByteArrayBody HttpClient is able to calculate the total request content length and delineates the message using Content-Length, while when using InputStreamBody HttpClient has to resort to content chunking (using Transfer-Encoding header). I suspect the server side script is simply unable to handle requests that do not have a Content-Length header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get some form data from POST method. Here's the code
I am trying to post some data with jQuery Ajax, but the parameters in
Cross-post http://perlmonks.org/index.pl?node_id=979710 I'm trying to create a text file from some XML using Perl
Trying to post JSON data to Spring controller.. Not working at all JSP Code:
I'm trying to display some checkbox in a form after getting the data from
I am trying to post some java code snippets on wordpress.com using the following
I am trying to add some post-processing capabilities to a program. The rendering is
i'm trying to do some post/lazy evaluation of arguments on my strings. Suppose i've
I'm trying to get pre/post annotations working with a web application, but for some
Trying to post a screenshot in a tweet from within my app.. so far

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.