指定 http 请求/响应的区域设置

发布于 2024-08-26 07:06:21 字数 535 浏览 2 评论 0 原文

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

一种选择是简单地向客户端指定所有请求应发送的区域设置。一个更友好的选项似乎是允许客户端指定区域设置。

我考虑过:

a)使用接受语言http标头来编码此信息。

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

http://www.w3.org/International/questions/qa-accept-lang-locales 警告使用接受语言标头的限制,但大多数警告似乎都围绕来自浏览器的请求。就我而言,请求将来自其他应用程序。

非常感谢所有建议!

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.

I've considered:

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

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

All advice greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯 2024-09-02 07:06:21

您的直接选择是 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).

逆光下的微笑 2024-09-02 07:06:21

w3.org 上对此主题进行了精确而彻底的讨论。快速摘要:您可以使用该语言作为初步猜测,但请确保您的客户端可以更正您从中派生的区域设置,因为它可能是错误的。

There's a precise and thorough discussion on this topic on w3.org. Quick summary: You can use the language as a first guess, but make sure your client can correct the locale settings you derive from that, as it can be wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文