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
- php header Content-Type型別小結PHPHeader型別
- ios Request failed: unacceptable content-type: text/html"iOSAIHTML
- Error parsing HTTP request header--400 bad requestErrorHTTPHeader
- 記一次跨域post請求資料之preflight request跨域
- Request和Response的HTTPHeader中的Content-TypeHTTPHeader
- springcloud fegin獲取request header解決方案SpringGCCloudHeader
- 從response.header中提取cookie,在request裡新增cookieHeaderCookie
- 06-記錄網路請求Request failed: unacceptable content-type: text/plain(AFNetworking)AI
- java反射——FieldJava反射
- Content-Type一覽
- post 405 method not allowed
- 使用AFNetworking 2.0 請求資料時出現錯誤 Request failed: unacceptable content-type: text/html 解決方法AIHTML
- 理解HTTP之 content-typeHTTP
- http Content-Type 知多少HTTP
- HTTP Content-Type型別HTTP型別
- http content-type總結HTTP
- MySQL 之 ORDER BY FIELDMySql
- add field security
- yebis error ---depth of fieldError
- IE Firefox 瀏覽器重新整理和強制重新整理傳送的 HTTP Request Header(轉)Firefox瀏覽器HTTPHeader
- jQuery :headerjQueryHeader
- HTTP headerHTTPHeader
- HTTP協議中Content-TypeHTTP協議
- TypeScript 裡的 class fieldTypeScript
- tpextbuilder- Displayers[元件]- FieldUI元件
- ABAP指標field symbol!指標Symbol
- Field Parameter的設定
- MYSQL Space id in fsp header,but in the page header錯誤MySqlHeader
- mongoengine.errors.OperationError: Update failed (BSON field ‘no_cursor_timeout‘ is an unknown fieldGoErrorAI
- FND_REQUEST.SUBMIT_REQUEST和 FND_CONCURRENT.WAIT_FOR_REQUESTMITAI
- Inhomogeneous deployment for replicated sessions is not allowed.Session
- [ERROR]Space id in fsp header but in the page header一列ErrorHeader
- axios 修改Content-Type設定iOS
- HTTP狀態碼和content-typeHTTP
- 11-Overview-Field SelectorsView
- Lucene原始碼解析--Field類原始碼
- Exercise 5: Field data acquisition and analysisUI