Getting "411 Length Required" after a PUT request from HTTP Client

41,019

Yes, the issue related to Content-Length. HTTP Error 411 means

The server refuses to accept the request without a defined Content- Length. The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message.

So when you send an empty RequestBody in POST/PUT Method then you also need to send Content-Length:0. So add this header in your request. I don't think this header will cause a problem of you added into Request Object.

Share:
41,019
Limbo Exile
Author by

Limbo Exile

Limbo Exile

Updated on July 12, 2022

Comments

  • Limbo Exile
    Limbo Exile almost 2 years

    I am working on a Java program that implements an HTTP Client. I test it sending requests to a server. GET, POST and DELETE requests work ok. For example after a POST request I get an output

    Data extracted:
    {"status":{"message":"ok"}}
    

    and the database reflects the changes made.

    After a PUT request, however I get the following html markup of a webpage indicating an error.

    Data extracted:
    <html>
    <head><title>411 Length Required</title></head>
    <body bgcolor="white">
    <center><h1>411 Length Required</h1></center>
    <hr><center>nginx/1.2.6</center>
    </body>
    </html>
    

    and accordingly no changes in the database.

    I found that this can have something to do with the Content-Length header, but I'm not sure. After trying to add this header my program waits for a minute and then throws an exception informing that it couldn't handle the server response.

    I can also provide any code or stack trace if needed.

  • Limbo Exile
    Limbo Exile about 11 years
    I tried this also, what I get in this case is Data extracted: {"status":{"message":"Content type 'application/octet-stream' not supported"}} and still no changes in database
  • Sachin
    Sachin about 11 years
    This is another issue which is related to Content-type. It may be possible that your server is not reporting the proper mime types or not supported this content-type
  • Limbo Exile
    Limbo Exile about 11 years
    I contacted the server and they informed me that they tested the same PUT request and it works with their implementation of HTTP Client. The thing is I use a dedicated Java ME platform and I assume there is a bug in my version of HTTP Client. What I cannot understand is how does it work with POST then?
  • Sachin
    Sachin about 11 years
    Try to get Content-Type Header value from whoever successfully put the request. I think it just a simple mistake of Header values in your request