php 405跳转,php – 返回HTTP 405的CORS预检请求
我正在嘗試創建一個RESTful Web服務,并且已經停止實現PUT請求.我嘗試過但未能在本網站上關注其他答案以及Mozilla的各種文章.
該請求是從域wwwtest.dev-box生成的,它將轉到test.dev-box(基本上是一個調用后端應用程序的前端應用程序).以下是我從Live HTTP標頭中捕獲的標頭:
http://test.dev-box/resource/v1/data/user/1
OPTIONS /resource/v1/data/user/1 HTTP/1.1
Host: test.dev-box
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://wwwtest.dev-box
Access-Control-Request-Method: PUT
Connection: keep-alive
HTTP/1.1 405 Method Not Allowed
Date: Wed, 16 Oct 2013 16:15:58 GMT
Server: Apache/2.2.15 (Red Hat)
x-powered-by: PHP/5.3.27
Access-Control-Allow-Origin: http://wwwtest.dev-box
Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS
Access-Control-Max-Age: 1728000
Content-Length: 0
Allow: PUT
Cache-Control: no-cache
Connection: close
Content-Type: text/html; charset=UTF-8
我正在使用一個框架,所以一切都被路由到web.php,它在頁面頂部包含以下代碼(取自this MDN article):
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
header('Access-Control-Allow-Origin: http://wwwtest.dev-box');
header('Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS');
header('Access-Control-Max-Age: 1728000');
header("Content-Length: 0");
header("Content-Type: text/plain");
} else {
header("HTTP/1.1 403 Access Forbidden");
header("Content-Type: text/plain");
}
在我的代碼發出PUT請求之前,它首先發送CORS預檢OPTIONS請求(從上面的捕獲中可以看到).應該將必要的標題附加到響應并告訴請求者允許PUT.不幸的是,正如您從上面的響應標頭中可以看到的那樣,即使PUT在響應access-control-allow-methods中,它仍然返回405 Method Not Allowed.
這是我正在使用的框架的.htaccess文件(Silex):
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ web.php [QSA,L]
總結
以上是生活随笔為你收集整理的php 405跳转,php – 返回HTTP 405的CORS预检请求的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 运算验证码类,php 数学运算验
- 下一篇: 开启php soap,php soap