Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes an HTTP 405 "invalid method (HTTP verb)" error when POSTing a form to PHP on IIS?

Tags:

php

iis

iis-6

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:

The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

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.

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.

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?

like image 876
drewm Avatar asked Sep 09 '09 14:09

drewm


People also ask

How do I fix the 405 method not allowed error in IIS?

If you don't need to use WebDAV, then the easiest and the best way to fix "405 method not allowed" issue is to remove WebDAV from your system. You can easily get this done in "Turn Windows Features On or Off" simply un-ticking the checkbox.

How do you fix 405 HTTP verb used to access this page is not allowed?

On the Request Filtering page, switch to the "HTTP Verbs" tab - if you see that "DELETE" has "Allowed" set to False, this is the cause. Remove this entry or changing it to explicitly be allowed will fix the issue.

What is invalid method HTTP verb?

The error message "HTTP Error 405.0 - Method Not Allowed" means that the request was sent to a page that can't handle a POST request.

What does 405 HTTP verb used to access this page is not allowed mean?

"405 - HTTP verb used to access this page is not allowed". 405 means that your Web Server is not recognizing the HTTP method(GET,POST,HEAD etc.) in the request.


4 Answers

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'); 

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.

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 could then resolve the redirect to a default document as is no longer attempting to POST to a directory.

like image 105
drewm Avatar answered Oct 02 '22 01:10

drewm


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.

like image 27
Boyd White Avatar answered Oct 02 '22 02:10

Boyd White


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.

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)

like image 36
Andiih Avatar answered Oct 02 '22 02:10

Andiih


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

like image 32
David Carrington Avatar answered Oct 02 '22 02:10

David Carrington