Invalid cookie header : Unable to parse expires attribute when expires attribute is empty
If you do not mind altering the CookieSpec
you can supply your own, more lenient, subclass.
First, create a lenient CookieSpec
that will accept null
and empty values for the expires
attribute, like this:
class LenientCookieSpec extends BrowserCompatSpec {
public LenientCookieSpec() {
super();
registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler(DATE_PATTERNS) {
@Override public void parse(SetCookie cookie, String value) throws MalformedCookieException {
if (TextUtils.isEmpty(value)) {
// You should set whatever you want in cookie
cookie.setExpiryDate(null);
} else {
super.parse(cookie, value);
}
}
});
}
}
Now you need to register & choose this new CookieSpec
in your HTTP client.
DefaultHttpClient client = new DefaultHttpClient();
client.getCookieSpecs().register("lenient", new CookieSpecFactory() {
public CookieSpec newInstance(HttpParams params) {
return new LenientCookieSpec();
}
});
HttpClientParams.setCookiePolicy(client.getParams(), "lenient");
Something "like this" could work for you.