我正在嘗試將請求從角度前端發(fā)送到由Spring后端公開的REST控制器。REST 控制器具有注釋。@CrossOrigin我正在使用 Http 客戶端從角度應(yīng)用程序發(fā)送請求。請求: const httpOptions = {
headers: new HttpHeaders({
'Authorization': 'Basic ' + basicAuthHeader,
})
}; return this.http.get(this.address + this.addressStorage.loginEndpoint + '/' + playerName, httpOptions);結(jié)果:Access to XMLHttpRequest at 'xxx' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.郵遞員發(fā)出的相同請求給出了正確的回應(yīng)。我的假設(shè):我已經(jīng)使用chrome開發(fā)工具檢查了網(wǎng)絡(luò)選項(xiàng)卡:問題是否是由發(fā)送選項(xiàng)請求而不是 GET 請求并且 CORS 僅允許 GET 方法這一事實(shí)引起的?假設(shè)我的猜測是正確的,那么將此組件添加到彈簧啟動應(yīng)用程序中會解決我的問題嗎?
來自彈性應(yīng)用中被 CORS 策略阻止的有角度應(yīng)用的請求
哆啦的時(shí)光機(jī)
2022-09-22 16:31:30