Android bug in setting date header on request

Last day I was working with a colleague in the development of a mobile app that relies on a rest web service that requires the setting of the Date header in the request (for authentication purposes). No matter how we set it, the request arrived to the web service with a null date header. After much trouble we found that if the date header was valorized after any other header, the request nullifies it. Setting the date before anything else worked like a charm. This strange behaviour happened only on the android application. The local test client didn't have that problem (a simple Java program).

So, if you have trouble settings the date header in an android application request, try put it first, like this:

request.addHeader("Date", new Date().toString());
request.addHeader("other-header", "some-value"));

Hope it can help someone.

Tags: