Saturday, March 27, 2010

OAuth Signpost on Android gives "411 Length Required"

Signpost is a great library to quickly get OAuth login working. Makes the modern APIs quickly mashable.

I got it working on desktop for newly enabled Google Reader OAuth login mechanism. (source here)

But similar code won't run inside Android emulator. And it failed giving a high level exception OAuthCommunicationException while getting request token (1st step). After looking into Signpost code, I found this was a wrapper exception around some low level IOException. After modifying and rebuilding Signpost jar for debug statements, and jumping through several workarounds (which I am too lazy to document), I found the real root cause was the Google login server returning "411 Length required" response.

That was surprising, especially because SignPost was explicitly setting "Content-Length:0" header on that request. I tried NOT setting Content-Length, no joy. Searched a lot for oauth + signpost + 411, but no definite solution. Finally I found this post. It still has no explanation and solution, but it has a work around that worked for me.

I had to change the HTTP request from POST to GET.

Thankfully Google login server accepts the OAuth requests in both kind so that worked out for now.

It still puzzles me why should it show up only in my Android App.