如何解决 HTTP 错误 405

Posted

技术标签:

【中文标题】如何解决 HTTP 错误 405【英文标题】:How to Solve HTTP Error 405 【发布时间】:2014-11-23 07:39:00 【问题描述】:

我在尝试使用 php post 一个小表单时收到 HTTP 错误 405。代码如下。我该如何解决这个问题?

  <div class="quiz-section">
            <form action="quiz.php" method="post">
                #################
            <input type="submit" class="btn blue" name="submitQuiz" value="Submit" />
        </form>
   </div>





<?php
    if (isset($_POST['submitQuiz'])) 
        if(isset($_POST['quest1'])&&isset($_POST['quest2'])&&isset($_POST['quest3']))
        
            if(($_POST['guestName']!="")&&($_POST['guestEmail']!=""))

                $to      = 'a######@yahoo.com';
                $subject = 'Quiz Answer Submission';
                $message = "Submited by: ".$_POST['guestName']." From email: ".$_POST['guestEmail']." Answers are: ".$_POST['quest1'].", ".$_POST['quest2'].", ".$_POST['quest3'];

                $headers = 'From: j#####@live.in' . "\r\n" .
                    'Reply-To: '.$_POST["guestEmail"] . "\r\n" .
                    'X-Mailer: PHP/' . phpversion();

                mail($to, $subject, $message, $headers);
                echo "Thanks for your submission. We successfully received your answers. Stay tuned.";
                //header("Location: index.html#quiz-questions?status=Success");
            
            else
                    echo "Please go back and answer all quiz questions";
            
        
        else
                echo "Please fill all the fields and answer to all questions";
                //header("Location: index.html#quiz-questions?status=Error");
        
    
?>

错误信息是:

The page cannot be displayed

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

Contact the Web site administrator if you believe that this request should be allowed.
Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
HTTP Error 405 - The HTTP verb used to access this page is not allowed.
Internet Information Services (IIS)

Technical Information (for support personnel)

Go to Microsoft Product Support Services and perform a title search for the words HTTP and 405.
Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Setting Application Mappings, Securing Your Site with Web Site Permissions, and About Custom Error Messages.

【问题讨论】:

405 HTTP Error - PHP POST 的可能重复项 &amp;&amp; isset.... 语句中添加空格,同时检查文件权限 @TML,没有正确答案! "为 PHP 文件添加 POST 动词"? 【参考方案1】:

我认为最可能的解释是 .php 文件未映射到 IIS 安装中的 POST 请求。 This guide 解释了如何映射扩展。

【讨论】:

这没有帮助。有没有办法在 Godaddy 中配置 ISS? 我认为问题一定是其他的。我原以为 PHP 会在共享主机中正确配置,或者根本不配置。 几天前它还在工作,突然间开始显示此错误。【参考方案2】:

我将 Windows 主机更改为 Linux,它对我来说效果很好。不知道 Winows 主机和 IIS 有什么问题。我的是用于 Windows 主机的 IIS 6。但是 Linux Hosting 一切都很好。

【讨论】:

以上是关于如何解决 HTTP 错误 405的主要内容,如果未能解决你的问题,请参考以下文章

jersey rest post 访问为http 405 异常如何解决

发布到 Google 脚本时如何修复“HTTP 405”?

网页提示错误代码405。是啥意思?如何解决?求高人指点。。

HTTP Status 405 错误

如何解决错误 405 方法不允许,用于 django graphql 服务器并在前端反应 axios

DioError [DioErrorType.RESPONSE]: Http 状态错误 [405] [已解决]