Question

In my project I use Apache's HttpComponents to connect to a server. The following code creates the HttpClient.

HttpParams params = new BasicHttpParams();
params.setParameter("http.language.Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3");
HttpProtocolParams.setUserAgent(params, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1003.1 Safari/535.19 Awesomium/1.7.1");

DefaultHttpClient client = new DefaultHttpClient(params);

But when I execute a request, the Accept-Language field is not sent. Just the following:

2013/04/06 20:52:07:129 MESZ [DEBUG] headers - >> GET /ws/search.json?text=&levelmin=0&levelmax=80&offset=1 HTTP/1.1
2013/04/06 20:52:07:129 MESZ [DEBUG] headers - >> Host: tradingpost-live.ncplatform.net
2013/04/06 20:52:07:129 MESZ [DEBUG] headers - >> Connection: Keep-Alive
2013/04/06 20:52:07:129 MESZ [DEBUG] headers - >> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1003.1 Safari/535.19 Awesomium/1.7.1
2013/04/06 20:52:07:129 MESZ [DEBUG] headers - >> Cookie: s=abcdefg

Is it a bug or did I do something wrong? I just want to have a "global" accept-language field (for all requests I send from one client).

Any help would be welcome

Was it helpful?

Solution

I was not able to fix that problem, but here's a workaround for anyone issuing the same problem: Create a central method like

void prepareHttpRequest(HttpRequest request){
    request.addHeader("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3");
}

You have to do that for every POST-or GET-request you do. I know that it's not very elegant, but my only solution,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top