Apache 上的内容类型:JSON 的 http 请求是否需要任何特定的处理程序?

发布于 2024-10-24 04:29:08 字数 793 浏览 4 评论 0原文

我的请求标头:

GET /abs/ad-content/id/1277954_1 HTTP/1.1
Host: myhost.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept: application/json, text/javascript, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/json; charset=utf-8
X-Requested-With: XMLHttpRequest

请注意:

Content-Type: application/json; charset=utf-8

但我的服务器似乎无法处理它。

$request->getHeader('Content-Type');

服务器返回空。

我是否需要添加一些处理程序/Mime 类型才能使其正常工作?

编辑:此标头存在于我的 Windows Apache 本地主机上,但在 Bluehost Apache 共享服务器上缺失。

My request header :

GET /abs/ad-content/id/1277954_1 HTTP/1.1
Host: myhost.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept: application/json, text/javascript, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/json; charset=utf-8
X-Requested-With: XMLHttpRequest

please note:

Content-Type: application/json; charset=utf-8

But it seems my server can not process it.

$request->getHeader('Content-Type');

is returned empty by server.

Do I need to add some handler/Mime Type to get it work?

Edit: This header is present on my windows Apache localhost but missing on Bluehost Apache shared server.

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

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

发布评论

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

评论(1

那请放手 2024-10-31 04:29:08

一般来说,GET 请求不会有正文因为它是一种安全方法,仅供参考检索:

特别是,已经建立了 GET 和
HEAD 方法不应该具有采取行动的意义
除了检索之外。这些方法应该被认为是“安全的”。
这允许用户代理代表其他方法,例如 POST、PUT
并以特殊方式删除,以便用户了解
事实上,正在请求执行可能不安全的操作。

所以我猜 Apache 或您使用的编程语言/框架会跳过/省略任何 实体标头字段,因为它不需要任何包含实体。

In general, it is not expected that a GET request has a body as it is meant to be a safe method only for information retrieval:

In particular, the convention has been established that the GET and
HEAD methods SHOULD NOT have the significance of taking an action
other than retrieval. These methods ought to be considered "safe".
This allows user agents to represent other methods, such as POST, PUT
and DELETE, in a special way, so that the user is made aware of the
fact that a possibly unsafe action is being requested.

So I guess Apache or the programming language/framework you are using skips/omits any entity header fields as it doesn’t expect any containing entity.

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