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 4025790
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:53:25+00:00 2026-05-20T10:53:25+00:00

Am testing with a client who send me a HTTP request with no content

  • 0

Am testing with a client who send me a HTTP request with no content length header but has a content.

How do I extract this content without the help of contentlength header?

  • 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-05-20T10:53:26+00:00Added an answer on May 20, 2026 at 10:53 am

    I’ve kept the original answer for completeness, but I’ve just been looking in the HTTP RFC (2616) section 4.3:

    The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request’s message-headers. A message-body MUST NOT be included in a request if the specification of the request method (section 5.1.1) does not allow sending an entity-body in requests. A server SHOULD read and forward a message-body on any request; if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.

    So if you haven’t got a content length, you must have a Transfer-Encoding (and if you haven’t, you should respond with a 400 status to indicate a bad request or 411 (“length required”)). At that point, you do what the Transfer-Encoding tells you 🙂

    Now if you’re dealing with a servlet API (or a similar HTTP API) it may well handle all this for you – at which point you may be able to use the techique below to read from the stream until it yields no more data, as the API will take care of it (i.e. it won’t just be a raw socket stream).

    If you could give us more information about your context, that would help.


    Original answer

    If there’s no content length, that means the content continues until the end of the data (when the socket closes).

    Keep reading from the input stream (e.g. writing it to a ByteArrayOutputStream to store it, or possibly a file) until InputStream.read returns -1. For example:

    byte[] buffer = new byte[8192];
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    int bytesRead;
    while ((bytesRead = inputStream.read(buffer)) != -1)
    {
        output.write(buffer, 0, bytesRead);
    }
    // Now use the data in "output"
    

    EDIT: As has been pointed out in comments, the client could be using a chunked encoding. Normally the HTTP API you’re using should deal with this for you, but if you’re dealing with a raw socket you’d have to handle it yourself.

    The point about this being a request (and therefore the client not being able to close the connection) is an interesting one – I thought the client could just shut down the sending part, but I don’t see how that maps to anything in TCP at the moment. My low-level networking knowledge isn’t what it might be.

    If this answer turns out to be “definitely useless” I’ll delete it…

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

Sidebar

Related Questions

The Django docs ( http://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.post ) say to do this: >>> c = Client()
I use wcf test client for testing my wcf services, but it has some
I have a testing PDA running on WM6.0. But my client uses WM5.0. Is
I'm creating an EnityList to do some client side testing with my ViewModel. Something
I'm currently testing a .NET 2.0 client application for Windows 7 Software Logo compliance
I've got a client that, during testing, is giving me conflicting information. I don't
I'm unit testing a demo application, which is a POP3 client. The POP3 client
I am testing my socket programs at home, in local network. Server and client
Testing: return request.getCookies() == null; is not an appropriate way test. Is there another
I've a client testing the full text (example below) search on a new Oracle

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.