幾個小時以來,我一直試圖控制 CORS ......來自一個試圖解決 php rest api 的 Angular 專案。問題,預檢失敗。身份驗證應該通過不記名令牌完成,我也從后端獲得。之后我嘗試發送這個然后相處融洽。
observable
.pipe(
switchMap(token => {
return this.http.get<any>(this.authService.getBackendPath() 'menuCategory', {
headers: new HttpHeaders({
Authorization: `Bearer ${token}`
})
});
}),
tap(res => console.log(res))
)
.subscribe();
附件是來自服務器的回應。
https://i.stack.imgur.com/WSl5o.png
在后端,我已經發布了所有可能的內容。
header('Content-Type: application/json, charset=utf-8');
header('Cache-Control: no-transform,public,max-age=300,s-maxage=900');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Method: POST, GET, OPTIONS');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers','Content-Type, Authorization, Access-Control-Allow-Origin, Origin, X-Requested-With, Access-Control-Allow-Credentials, authorization');
至于CORS,我還是有點經驗不足,不知道具體怎么解決這個問題。有人有什么想法嗎?
uj5u.com熱心網友回復:
瀏覽器說:
這是一個 OPTIONS 請求。我可以提出包含我的憑據的請求嗎?
服務員說:
第403章 禁止!你不能提出你剛剛提出的要求
您需要從要驗證的要求中排除使用 OPTIONS 方法的請求。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/513538.html
標籤:php有角度的科尔斯预检
