什么导致 HTTP 405“无效方法(HTTP 动词)"?在 IIS 上将表单发布到 PHP 时出错? [英] What causes an HTTP 405 "invalid method (HTTP verb)" error when POSTing a form to PHP on IIS?

查看:30
本文介绍了什么导致 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 时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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