服务器将POST请求视为GET [英] POST Requests seen as GET by server

查看:114
本文介绍了服务器将POST请求视为GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里遇到了一个非常奇怪的问题.将帖子请求发送到我的PHP脚本

Got a really strange problem here. When sending post requests to my PHP script

$_SERVER['REQUEST_METHOD'] 

返回"GET"而不是"POST".

returns "GET" instead of "POST".

对于其他所有REST方法都可以正常工作

It works fine for every other REST method

这就是我得到的

GET -> GET
POST-> GET
PUT -> PUT
DELETE -> DELETE

它仅在我的一台服务器上发生,因此我假设这是一个Apache问题,并且我设法弄清楚,仅当我在网址中添加"www"时,它才会发生.

It only happens on one of my servers so i'm assuming it's an apache problem and i've managed to figure out that it only happens if I add "www" to my url.

www.something.com

www.something.com

引起问题,但是

something.com

something.com

不是

我已经在同一台服务器上的不同站点上进行了测试,并且得到了相同的东西,所以我假设它是全局配置.

I have tested on different sites on the same server and I get the same thing so I'm assuming it's global config.

任何想法

推荐答案

作为

As the HTTP spec says for response codes 301 and 302:

注意:由于历史原因,用户代理可以更改请求方法 从POST到GET进行后续请求.如果这种行为是 不需要,可以使用307(临时重定向)状态代码 代替

Note: For historic reasons, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead

第三种(但不太可能)的可能性是,您收到对初始URI的303响应.解决方案是双重的:

A third (but unlikely) possibility is you're getting a 303 response to the initial URI. The solution is twofold:

  • 将受您控制的客户端配置为POST到规范URI,以便根本不重定向它们.
  • 在这种情况下,将服务器配置为使用307而不是301/302进行重定向.

这篇关于服务器将POST请求视为GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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