簡體   English   中英

即使我有正確的標題,也不允許使用 CORS 405 方法(我認為)

[英]CORS 405 Method Not Allowed even though I have the right headers (I think)

我需要更多的關注。 我的預檢請求因 405 Method Not Allowed 而失敗。

據我所知它應該可以工作。 這是我的要求:

OPTIONS http://diffDomain/spf/v1/user/user@example.com/password/change 
HTTP/1.1
Host: diffDomain.com
Connection: keep-alive
Access-Control-Request-Method: PUT
Origin: http://www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
Accept: */*
Referer: http://www.example.com/appName/index.html
Accept-Encoding: gzip, deflate
Accept-Language: en-US,es-US;q=0.8,es;q=0.6,en;q=0.4

回復:

HTTP/1.1 405 Method Not Allowed
Date: Thu, 14 Sep 2017 02:06:30 GMT
Server: Apache/2.4.7 (Ubuntu)
Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, DELETE
X-Powered-By: PHP/5.5.9-1ubuntu4.20
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, api_key, Authorization, Accept
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json

我正在等待訪問服務器,以便我可以將 Access-Control-Request-Method 添加到Access-Control-Allow-Headers行。 那會有幫助嗎?

我只是需要一些眼睛,因為我今天已經調試了幾個小時,但我還沒有訪問服務器的權限。

當我按照下面的@sideshowbarker 建議進行操作時,我得到:

> curl -i -X OPTIONS http://diffDomain.com/spf/v1/user/user@example.com/password/change
HTTP/1.1 500 Internal Server Error
Date: Thu, 14 Sep 2017 21:25:39 GMT
Server: Apache/2.4.7 (Ubuntu)
Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, DELETE
X-Powered-By: PHP/5.5.9-1ubuntu4.20
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, api_key, Authorization, Accept, Content-Type, api_key, Authorization, Accept, Access-Control-Request-Method, Origin
Content-Length: 0
Connection: close
Content-Type: application/json

我不知道你的后端是什么樣子,但我建議你添加一個中間件來攔截每個 OPTIONS 並返回 200 響應並移動到下一個請求。

為了澄清這里是一個這個問題與基於Laravel的API。

我希望它有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM