使用AngularJS調用RESTFUL API。AngularJS在CORS預檢響應後未發送請求
在IOS上使用Chrome瀏覽器時,CORS預檢請求(選項請求)Accept
標頭設置爲*/*,image/webp
。響應恢復正常,但實際的GET請求永遠不會被髮送。正如你在響應中看到的,Content-Type
頭文件被設置爲image/webp
,我懷疑這會導致AngularJS中的問題隨GET請求一起前進。
我的假設是否正確?如果是這樣,是否強制服務器將Content-Type
設置爲其他內容的解決方案?
完整請求報頭:
OPTIONS http://www.example.com:8080/resourceABC HTTP/1.1
Host: www.example.com:8080
Connection: keep-alive
Access-Control-Request-Headers: accept, authorization, origin
Access-Control-Request-Method: GET
Origin: http://www.example.com
Accept: */*,image/webp
Referer: http://www.example.com/
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) CriOS/38.0.2125.67 Mobile/12B411 Safari/600.1.4
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
完整響應頭:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Allow: GET,OPTIONS,HEAD
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS
Access-Control-Allow-Headers: X-HTTP-Method-Override, Content-Type, x-requested-with, authorization, accept
Access-Control-Max-Age: 3600
Content-Type: image/webp
Content-Length: 0
Date: Wed, 29 Oct 2014 19:26:37 GMT
我有這個相同的問題,我沒有修復,你有沒有設法解決這個問題? – Skintkingle 2015-10-22 16:36:00
那麼,我不清楚錯誤在哪裏,無論是使用Spring還是Chromium。我記錄了鉻缺陷429507,但沒有真正遵循。我結束瞭解決問題服務器端,這裏做這個破解:(僞代碼) if(method ==「OPTIONS」&& header ==「Accept」){header.contains(「image/webp」) ){ headers.remove(「Content-Type」); headers.add(「Content-Type」,「text/plain」); } } – Marc 2015-10-23 18:58:23