Android HTTP calls not setting Accept-Language headers?

南笙酒味 提交于 2019-12-12 15:22:07

问题


I have set my Google Nexus 4 device to the Français (France) setting, and am browsing a site that is localized via the Accept-Language HTTP header from the client.

However, when I look at the Accept-Language settings arriving at the server, I see is is just en-US.

If I use the Dolphin browser to view the same site on the same device, the header comes in as fr-FR,en-US;q=0.8, and the site displays correctly in French.

The Nexus 4 is a development device, running Android 4.4.2; Nexus 4 Build/KOT49H. The version of Chrome is 32.0.1700.99.

Does anyone know how I get Chrome to honor the device's Language setting?

I am developing an Android app, and was expecting that the HTTP client org.apache.http.client.HttpClient would honor setting the Accept-LanguageHTTP header when calling my web service. However it doesn't, and I'm trying to figure out why.

The Chrome browser also exhibits this behavior, so I thought I would see if anyone else has this issue (posting my code is a little convoluted, and not really appropriate).

Do I really have to explicitly set the HTTP headers based on what I get back from Locale.getDefault().getLanguage() ?

It seems that is not the intent of being able to set the user's language via the Android settings.


回答1:


So are you doing the following steps? (I'd imagine from your question that you already are, but I want to check because this works for me)

  HttpClient client = new DefaultHttpClient();
  HttpPost request = new HttpPost(webServiceUrl);
  request.addHeader("Accept-Language", "fr");
  HttpResponse response = client.execute(request);


来源:https://stackoverflow.com/questions/21345363/android-http-calls-not-setting-accept-language-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!