以我角控制器代碼我的HTTP GET方法不與頭工作,但同樣的請求在郵遞員工作角JS get請求與包頭中表示錯誤CORS
$http({
method: 'GET',
url: 'http://localhost:8080/api/profiles',
headers: {
'Authorization': 'Bearer 78954642-sf25-4sd6-sdf2-99582369d5af',
'Content-Type':'text/plain'
}
}).then(function(success) {
console.log(success);
}, function(error) {
});
顯示以下錯誤
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://quotebuilder' is therefore not allowed access. The response had HTTP status code 401.
我的請求頭
OPTIONS /api/profiles HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Access-Control-Request-Method: GET
Origin: http://quotebuilder
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Access-Control-Request-Headers: authorization
Accept: */*
Referer: http://quotebuilder/login
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8
什這裏錯了嗎?請幫我解決問題
您需要從chrome安裝CORS插件,或者應該從API啓用CORS。 – Rajesh
我認爲你可以傳遞響應頭文件,它應該可以工作。當我在我的'response'頭文件中添加'.headers(Access-Control-Allow-Methods「,」GET,POST,DELETE,PUT,OPTIONS「)時,它對我有效,如果這樣做不起作用,那麼編輯你的網頁。 xml文件(如果使用的是tomcat) –