405錯誤的解決方法

來源:酷知科普網 1.71W

可能在現實生活中很多人都不會405錯誤的解決方法,遇到時又很麻煩,所以,下面小編就為大家帶來一篇關於javaWeb中405錯誤的解決方法。

405錯誤的解決方法

操作方法

(01)例1:用linux下的curl命令傳送POST請求給Apache伺服器上的HTML靜態頁. 程式碼如下:[root@localhost ~]# curl -d 11=1    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">   <HTML>      <HEAD>          <TITLE>405 Method Not Allowed</TITLE>      </HEAD>      <BODY>          <H1>Method Not Allowed</H1>          The requested method POST is not allowed for the URL /.<P>          <HR>          <ADDRESS>Apache/1.3.37 Server at Port 80</ADDRESS>      </BODY>   </HTML>

405錯誤的解決方法 第2張

(02)例2:用linux下的curl命令傳送POST請求給nginx伺服器上的HTML靜態頁. 程式碼如下:[root@localhost ~]# curl -d 11=1    <html>      <head><title>405 Not Allowed</title></head>      <body bgcolor="white">          <center><h1>405 Not Allowed</h1></center>          <hr><center>nginx/1.2.0</center>      </body>   </html>

405錯誤的解決方法 第3張

(03)但在有些應用中,需要使靜態檔案能夠響應POST請求。對於Nginx,可以修改配置檔案,改變“405錯誤”為“200 ok”,並配置location來解決,方法如下:. 程式碼如下:server    {        listen  80;        server_name ;        index ;        root  /opt/htdocs;        if (-d $request_filename)        {            rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;        }        error_page  405 =200 @405;        location @405        {            root  /opt/htdocs;        }        location ~ .*        {            include conf/;                fastcgi_pass  ;            fastcgi_index ;        }    }

405錯誤的解決方法 第4張

(04)當然也可以修改nginx原始碼來解決修改原始碼,重新編譯安裝nginx編輯nginx原始碼. 程式碼如下:[root@localhost ~]# vim src/http/modules/ngx_http_static_module.c

405錯誤的解決方法 第5張

(05)修改: 找到下面一段註釋掉. 程式碼如下:/*   if (r->method & NGX_HTTP_POST)   {      return NGX_HTTP_NOT_ALLOWED;   }   */

405錯誤的解決方法 第6張

(06)最後按照原來的編譯引數,重新編譯安裝nginx,即可。

405錯誤的解決方法 第7張
熱門標籤