Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight respon
一、問題:
跨域請求中包含自定義header欄位時,瀏覽器console報錯。
Request header field xfilesize is not allowed by Access-Control-Allow-Headers
1 想要實現前後分離,首先得跨域
2 怎麼跨域,在後端中 servlet 或 filter 設定請求頭,然後就出問題了
3 has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response
已被CORS策略阻止:響應請求頭,不允許請求標頭欄位內容型別
4 問題就出在這,思考了很久,程式碼好像沒錯啊
response.setHeader("Access-Control-Allow-Origin");
response.setHeader("Access-Control-Allow-Credentials", "true");
5 百度了之後,原因:
包含自定義header欄位的跨域請求,瀏覽器會先向伺服器傳送OPTIONS請求,探測該伺服器是否允許自定義的跨域欄位。
如果允許,則繼續實際的POST/GET正常請求,否則,返回標題所示錯誤
6 說白了就是,要有自定義請求頭和響應頭完成跨域互動,瀏覽器要求的(瀏覽器版本新)
7 java 自定義請響應頭,給瀏覽器一個響應,帶這個請求頭的放行
// /* 允許跨域的請求頭 */ // 這裡 指定 自己起一個
response.setHeader("Access-Control-Allow-Headers", "Content-Type,Access-Control-Ajax-Headers");
response.setHeader("Access-Control-Ajax-Headers", "cros");// 自定義的
8 前端請求頭,和後端對應
{'Access-Control-Ajax-Headers': 'cors'}
相關文章
- 問題一:Content-Type header is not supportedHeader
- 記一次跨域post請求資料之preflight request跨域
- springcloud fegin獲取request header解決方案SpringGCCloudHeader
- Serialization of 'Closure' is not allowed
- 理解HTTP之 content-typeHTTP
- http Content-Type 知多少HTTP
- HTTP Content-Type型別HTTP型別
- MySQL 之 ORDER BY FIELDMySql
- axios 修改Content-Type設定iOS
- HTTP協議中Content-TypeHTTP協議
- mongoengine.errors.OperationError: Update failed (BSON field ‘no_cursor_timeout‘ is an unknown fieldGoErrorAI
- HTTP Header 詳解HTTPHeader
- http設定headerHTTPHeader
- HTML <header> 標籤HTMLHeader
- StreamCorruptedException: invalid stream headerExceptionHeader
- 新建分支 header區Header
- copying model and updating field of pydantic
- Field Parameter的設定
- 11-Overview-Field SelectorsView
- TypeScript 裡的 class fieldTypeScript
- tpextbuilder- Displayers[元件]- FieldUI元件
- HTTP狀態碼和content-typeHTTP
- “Host ‘xxxx‘ is not allowed to connect to this MySQL server“MySqlServer
- Host 'localhost' is not allowed to connect to this MySQL serverlocalhostMySqlServer
- spring boot 併發請求,其他系統介面,丟失request的header資訊【多執行緒、執行緒池、@Async 】Spring BootHeader執行緒
- header的安全配置指南Header
- Refused to set unsafe header "cookie"HeaderCookie
- http協議Content-Type型別表HTTP協議型別
- Nginx的client_header_buffer_size和large_client_header_buffers學習NginxclientHeader
- Exercise 5: Field data acquisition and analysisUI
- Neural Radiance Field (NeRF): A Gentle Introduction
- SAP產品的Field Extensibility
- Request物件物件
- Error: User gpmon is not allowed to login Command CenterError
- Allowed memory size 記憶體不足記憶體
- Host 'xxx' is not allowed to connect to this MySQL server.MySqlServer
- urllib.request.Request物件封裝請求物件封裝
- Git Fork Pull Request(PR)和Merge Request(MR)Git