指定http请求/响应的区域设置 [英] Specifying locale for http request/response

查看:583
本文介绍了指定http请求/响应的区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ReSTful Web服务,需要解析来自请求的区域设置敏感数据。此数据可以位于XML正文中,也可以位于查询字符串的一部分中。是否有任何通过哪种方法来确定数据的发送位置(以及扩展应该发送响应的区域)?

I have a ReSTful web service which needs to parse locale-sensitive data from the request. This data could either be in an XML body or part of the query string. Is there any acepted way of determining which locale the data is being sent in (and by extension the locale in which the response should be sent)?

一个选项就是向客户端指定应发送所有请求的语言环境。更友好的选择似乎是允许客户指定区域设置。

One option is simply to specify to the clients the locale in which all requests should be sent. A friendlier option seems to be to allow the client to specify the locale.

我考虑过:

a)使用accept-language http头来编码这些信息。

a) using the accept-language http header to encode this information.

b)使用XML POST的xml:lang属性,以及查询字符串的额外字段(例如...& locale = en-GB)

b) using the xml:lang attribute for XML POSTs, and an extra field for query strings (e.g. ...&locale=en-GB)

http://www.w3.org/International/questions/qa-accept-lang-locales 警告使用接受语言标题的限制,但大多数警告似乎以源自浏览器的请求为中心。在我的情况下,请求将来自其他应用程序。

http://www.w3.org/International/questions/qa-accept-lang-locales warns of limitations in using the accept-language header, but most of the warnings seem to center around requests originating from browsers. In my case the requests will come from other applications.

所有建议都非常感谢!

推荐答案

您的直接选择是Accept-Language,可能是Accept-Charset。另一个选择是使用将客户端IP映射到地理位置的数据库(尽可能)。这些数据库变得非常好。我想,但他们通常不是免费的(你需要付钱)。

Your immediate choice is Accept-Language and probably Accept-Charset. A further option is to used a database that maps the client IP to a geographic location (as far as possible). These databases have become quite good. I think, but they usually are not free (you need to pay).

这篇关于指定http请求/响应的区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆