本文介绍了Android HTTP调用未设置Accept-Language标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Google Nexus 4设备设置为Français (France)设置,并且正在浏览来自客户端的通过Accept-Language HTTP标头进行本地化的网站.

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.

但是,当我查看到达服务器的Accept-Language设置时,我看到的只是en-US.

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

如果我使用Dolphin浏览器在同一设备上查看同一站点,则标题为fr-FR,en-US;q=0.8,并且该站点以法语正确显示.

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.

Nexus 4是运行Android 4.4.2的开发设备; Nexus 4内部版本/KOT49H. Chrome的版本是32.0.1700.99.

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.

有人知道我如何获得Chrome才能使用设备的语言设置吗?

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

我正在开发一个Android应用程序,并且期望HTTP客户端org.apache.http.client.HttpClient在调用Web服务时愿意使用Accept-Language HTTP标头设置.但是事实并非如此,我正试图找出原因.

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.

Chrome浏览器也表现出这种行为,因此我想我是否应该看看其他人是否遇到此问题(发布我的代码有点令人费解,并且不合适).

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).

我真的必须根据从Locale.getDefault().getLanguage()返回的内容显式设置HTTP标头吗?

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

似乎并不是要通过Android设置来设置用户的语言.

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

推荐答案

您正在执行以下步骤吗? (从您的问题中我想您已经存在了,但是我想检查一下,因为这对我有用)

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);

这篇关于Android HTTP调用未设置Accept-Language标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:30