What causes an HTTP 405 quot;invalid method (HTTP verb)quot; error when POSTing a form to PHP on IIS?(什么导致 HTTP 405“无效方法(HTTP 动词)?在 IIS 上将表单发布到 PHP 时出错?)
问题描述
我在 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 时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么导致 HTTP 405“无效方法(HTTP 动词)"?在 I
基础教程推荐
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01