問題描述
我在 PHP (5.2.9-1) 應用程序中有一個表單,導致 IIS (Microsoft-IIS/6.0) 在發布時拋出以下錯誤:
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:
無法顯示您要查找的頁面,因為嘗試訪問時使用了無效方法(HTTP 動詞).
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.
這是一個 HTTP 405 狀態代碼.應用程序中的所有其他表單都可以工作,因此我相信 PHP 頁面的 IIS 'verbs' 設置是正確的.
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.
這是客戶的服務器,我無法訪問它來驗證設置或測試代碼.我所能做的就是發送客戶更換文件.IIS 服務器上的其他客戶沒有這樣的問題.
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.
表格非常簡單:
<form method="post" action="index.php">
... fields ...
</form>
什么會導致 IIS 僅在一種形式上拋出該錯誤,而在其他形式上卻能正常工作?
What can cause IIS to throw that error on one form only, but work fine on others?
推薦答案
我設法通過 FTP 訪問客戶的服務器,因此能夠找到問題所在.
I managed to get FTP access to the customer's server and so was able to track down the problem.
提交表單后,我對用戶進行身份驗證,然后重定向到應用程序的主要部分.
After the form is POSTed, I authenticate the user and then redirect to the main part of the app.
Util::redirect('/apps/content');
錯誤不是發生在表單的發布上,而是發生在緊隨其后的重定向上.出于某種原因,IIS 繼續假定重定向的 POST 方法,然后反對 POST 到 /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/content
as it's a directory.
錯誤消息從未表明是下一頁產生了錯誤 - 感謝 Microsoft!
The error message never indicated that it was the following page that was generating the error - thanks Microsoft!
解決方案是添加一個尾部斜杠:
The solution was to add a trailing slash:
Util::redirect('/apps/content/');
然后 IIS 可以將重定向解析為默認文檔,因為不再嘗試 POST 到目錄.
IIS could then resolve the redirect to a default document as is no longer attempting to POST to a directory.
這篇關于什么導致 HTTP 405“無效方法(HTTP 動詞)"?在 IIS 上將表單發布到 PHP 時出錯?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!