POST Requests seen as GET by server

旧巷老猫 提交于 2019-12-11 05:47:44

问题


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

$_SERVER['REQUEST_METHOD'] 

returns "GET" instead of "POST".

It works fine for every other REST method

so this is what I get

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

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.

I.e

www.something.com

causes the problem but

something.com

does not

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

Any thoughts


回答1:


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

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

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

  • Configure the clients which are under your control to POST to the canonical URI so they are not redirected at all.
  • Configure your server to redirect using 307 in this case instead of 301/302.


来源:https://stackoverflow.com/questions/19049223/post-requests-seen-as-get-by-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!