亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

發布約會/預訂 - CORS 政策問題

發布約會/預訂 - CORS 政策問題

瀟湘沐 2023-03-17 16:09:10
我嘗試發布一本包含預訂數據的字典。但是 chrome 記錄了這個錯誤:Access to XMLHttpRequest at 'http://localhost:8080/reservations' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.這很奇怪,因為我可以發布圖像、視頻、html 內容,因為我@CrossOrigin在控制器上方放置了注釋。但是對于這個特定的帖子請求,它似乎不起作用。休息控制器:@CrossOrigin(origins="http://localhost:4200",        maxAge=2000,allowedHeaders="header1,header2",        exposedHeaders="header1",allowCredentials= "false")@RestControllerpublic class ReservationsController {    private ReservationDao dao;    @Autowired    public ReservationsController(ReservationDao dao) {        this.dao = dao;    }    @PostMapping("/reservations")    public Map<String, String> bookReservation(@RequestBody Map<String, String> reservation) {        System.out.println(reservation);        return null;    }}angular api bookReservation方法: bookReservation(data) {    console.log(data);    const result = this.http.post(this.apiUrl + 'reservations', data).subscribe(      (val) => {        console.log('POST call succesful value returned in body',          val);      },      response => {        console.log('POST call in error', response);      },      () => {        console.log('The POST observable is now completed');      });    console.log(result);  }
查看完整描述

1 回答

?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

如果您只設置 allowedHeaders,您將允許此參數,如果它收到其他參數,它永遠不會發送交叉原始標頭,chrome 將拋出錯誤。

如果不需要,則應刪除 allowedHeaders、exposedHeaders 和 allowCredentials。


查看完整回答
反對 回復 2023-03-17
  • 1 回答
  • 0 關注
  • 98 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號