在 IIS 上将表单发布到 PHP 时,是什么导致 HTTP 405“无效方法(HTTP 动词)”错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1400210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What causes an HTTP 405 "invalid method (HTTP verb)" error when POSTing a form to PHP on IIS?
提问by drewm
I have one form in a PHP (5.2.9-1) application that causes IIS (Microsoft-IIS/6.0) to throw the following error when POSTed:
我在 PHP (5.2.9-1) 应用程序中有一个表单,它导致 IIS (Microsoft-IIS/6.0) 在发布时抛出以下错误:
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.
您正在查找的页面无法显示,因为尝试访问时使用了无效方法(HTTP 动词)。
It's an HTTP 405 status code. All other forms in the application work, so I believe that the IIS 'verbs' setting for PHP pages is correct.
这是一个 HTTP 405 状态代码。应用程序中的所有其他表单都可以工作,因此我相信 PHP 页面的 IIS 'verbs' 设置是正确的。
This is a customer's server, which I have no access to for verifying settings or testing code. All I can do is send the customer replacement files. Other customers on IIS servers have no such issue.
这是客户的服务器,我无法访问它来验证设置或测试代码。我所能做的就是发送客户更换文件。IIS 服务器上的其他客户没有这样的问题。
The form is perfectly straightforward:
表格非常简单:
<form method="post" action="index.php">
... fields ...
</form>
What can cause IIS to throw that error on one form only, but work fine on others?
什么会导致 IIS 仅在一种形式上抛出该错误,而在其他形式上正常工作?
采纳答案by drewm
I managed to get FTP access to the customer's server and so was able to track down the problem.
我设法通过 FTP 访问了客户的服务器,因此能够找到问题所在。
After the form is POSTed, I authenticate the user and then redirect to the main part of the app.
表单发布后,我对用户进行身份验证,然后重定向到应用程序的主要部分。
Util::redirect('/apps/content');
The error was occurring not on the posting of the form, but on the redirect immediately following it. For some reason, IIS was continuing to presume the POST method for the redirect, and then objecting to the POST to /apps/contentas it's a directory.
错误不是发生在表单的发布上,而是发生在紧随其后的重定向上。出于某种原因,IIS 继续假定重定向的 POST 方法,然后反对 POST 到,/apps/content因为它是一个目录。
The error message never indicated that it was the following page that was generating the error - thanks Microsoft!
错误消息从未表明是以下页面产生了错误 - 感谢 Microsoft!
The solution was to add a trailing slash:
解决方案是添加一个尾部斜杠:
Util::redirect('/apps/content/');
IIS could then resolve the redirect to a default document as is no longer attempting to POST to a directory.
然后 IIS 可以将重定向解析为默认文档,因为不再尝试 POST 到目录。
回答by Boyd White
I am deploying VB6 IIS Applications to my remote dedicated server with 75 folders. The reason I was getting this error is the Default Document was not set on one of the folders, an oversight, so the URL hitting that folder did not know which page to server up, and thus threw the error mentioned in this thread.
我正在将 VB6 IIS 应用程序部署到具有 75 个文件夹的远程专用服务器。我收到此错误的原因是未在其中一个文件夹上设置默认文档,这是一个疏忽,因此访问该文件夹的 URL 不知道要服务器哪个页面,因此引发了此线程中提到的错误。
回答by David Carrington
By any chance have you tried POST vs post? This support article suggests it can cause problems with IIS: http://support.microsoft.com/?id=828726
你有没有尝试过POST vs post?这篇支持文章表明它可能会导致 IIS 出现问题:http: //support.microsoft.com/?id= 828726
回答by Andiih
The acceptable verbs are controlled in web.config (found in the root of the website) in <system.web><httpHandlers>and possibly <webServices><protocols>. Web.config will be accessible to you if it exists. There is also a global server.config which probably won't. If you can get a look at either of these you may get a clue.
可接受的动词在 web.config(在网站的根目录中)中控制,<system.web><httpHandlers>并且可能在<webServices><protocols>. 如果存在,您可以访问 Web.config。还有一个可能不会的全局 server.config。如果您可以查看其中任何一个,您可能会得到一个线索。
The acceptable verbs can differ with the content types - have you set Content-type headers in your page at all ? (i.e. if your Content-type was application/json then different verbs would be allowed)
可接受的动词可能因内容类型而异 - 您是否在页面中设置了 Content-type 标题?(即,如果您的内容类型是 application/json,则将允许使用不同的动词)
回答by Bobby
I don't know why but its happened when you submit a form inside a page to itself by the POSTmethod.
我不知道为什么,但是当您通过该POST方法向自身提交页面内的表单时会发生这种情况。
So change the method="post"to method="get"or remove action="anyThings.any"from your <form>tag.
因此,更改method="post"为method="get"或action="anyThings.any"从您的<form>标签中删除。
回答by Waqleh
I had this issue with a facebook application that I was developing for a fan page tab. If anyone faces this issue with a facebook application then
我在为粉丝页面选项卡开发的 facebook 应用程序中遇到了这个问题。如果有人在 Facebook 应用程序中遇到此问题,那么
1-goto https://developers.facebook.com
1-转到https://developers.facebook.com
2-select the application that you are developing
2-选择您正在开发的应用程序
3-make sure that all the link to your application has tailing slash /
3-确保所有指向您的应用程序的链接都有尾部斜杠/
my issue was in the https://developers.facebook.com->Apps->MYAPPNAME->settings->Page Tab->Secure Page Tab URL, Page Tab Edit URL, Page Tab URL hope this will help
我的问题是在https://developers.facebook.com->Apps->MYAPPNAME->settings->Page Tab->Secure Page Tab URL、Page Tab Edit URL、Page Tab URL 希望这会有所帮助
回答by Doug McLean
As drewm himself said this is due to the subsequent redirect after the POST to the script has in fact succeeded. (I might have added this as a comment to his answer but you need 50 reputation to comment and I'm new round here - daft rule IMHO)
正如 drawm 本人所说,这是由于 POST 到脚本实际上成功后的后续重定向。(我可能已将此作为评论添加到他的回答中,但您需要 50 声望才能发表评论,而我是新来的 - 愚蠢的规则恕我直言)
BUT it also applies if you're trying to redirect to a page, not just a directory - at least it did for me. I was trying to redirect to /thankyou.html. What fixes this is using an absolute URL, i.e. http://example.com/thankyou.html
但是,如果您尝试重定向到一个页面,而不仅仅是一个目录,它也适用 - 至少对我来说是这样。我试图重定向到 /thankyou.html。解决此问题的是使用绝对 URL,即http://example.com/thankyou.html
回答by captainhero70
i had to change my form's POST to a GET. i was just doing a demo post to an html page, on a test azure site. read this for info: http://support.microsoft.com/kb/942051
我不得不将表单的 POST 更改为 GET。我只是在一个测试天蓝色的网站上对一个 html 页面做一个演示帖子。阅读此信息:http: //support.microsoft.com/kb/942051
回答by captainhero70
It sounds like the server is having trouble handling POST requests (get and post are verbs). I don't know, how or why someone would configure a server to ignore post requests, but the only solution would be to fix the server, or change your app to use get requests.
听起来服务器在处理 POST 请求时遇到问题(get 和 post 是动词)。我不知道如何或为什么有人会配置服务器以忽略发布请求,但唯一的解决方案是修复服务器,或更改您的应用程序以使用获取请求。
回答by Sam Monem
We just ran into this same issue. Our Cpanel has expanded from PHP only to PHP and .NET and defaulted to .NET.
我们刚刚遇到了同样的问题。我们的 Cpanel 已经从 PHP 扩展到 PHP 和 .NET,并默认为 .NET。
Log in to you Cpanel and make sure you don't have the same issue.
登录到您的 Cpanel 并确保您没有同样的问题。

