HTTP Response 411 Length Required, Http Client 4.0.1 Android

moonlightcheese picture moonlightcheese · Jul 9, 2010 · Viewed 7k times · Source

i'm sending an http request to the google reader api and getting an unusual response code. following the documentation, i've requested an auth code and included it in the header of every request. after performing the login, and getting an auth code, i tried accessing this url, which is part of the documentation:

http://www.google.com/reader/api/0/stream/items/contents

when i send the request, i get a 411 status code, which is supposed to mean "Length Required". the length, as i've found, is supposed to be the length, in octets, of the message body. there is no message body in this request. there is only a single header, the POST parameter i="item id" and the URL itself. i tried setting the "Content-Length" header to "0" and also to "-1" to no avail.

what's really interesting is that this same code worked fine before google changed their authorization procedure. it's apparent they've changed something else...

so my question is what EXACTLY would cause a 411 response code and how can i prevent it?

Answer

Nar Gar picture Nar Gar · Feb 24, 2012

This error happens only with POST and PUT request types, as these two (sort of) expect to have a request body that includes the request parameters (plain textual as well as attachments).

However as the documentation suggests, this is largely an obsolete value, and realistically the web services should handle requests without relying on Content-Length.

So it's not the problem of a request sender, but it is (I would say) a bug on the service side.

Nevertheless, setting a Content-Length (mind the proper capitalisation) request header to 0 should be the workaround.