当前位置:网站首页>A cross domain problem of golang
A cross domain problem of golang
2022-07-27 06:47:00 【lianyz1985】
goLang A cross domain problem of
Problem description
Access to XMLHttpRequest at ‘http://127.0.0.1:8888/base/captcha’ from origin ‘http://127.0.0.1:8080’ has been blocked by CORS policy: Cannot parse Access-Control-Allow-Headers response header field in preflight response.
127.0.0.1:8888 The cross domain policy of the backend is :
origin := c.Request.Header.Get("Origin")
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Access-Control-Allow-Headers", "Content-Type, AccessToken, X-CSRF-Token, Authorization, Token, x-token, x-user-id\"")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS,DELETE,PUT")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
After commenting out the third line
//c.Header("Access-Control-Allow-Headers", "Content-Type, AccessToken, X-CSRF-Token, Authorization, Token, x-token, x-user-id\"")
The error message is :
Access to XMLHttpRequest at ‘http://127.0.0.1:8888/base/captcha’ from origin ‘http://127.0.0.1:8080’ has been blocked by CORS policy: Request header field x-token is not allowed by Access-Control-Allow-Headers in preflight response.
Change the third line to :
c.Header("Access-Control-Allow-Headers", "*") // Allow access to all domains
Normal access .
The actual reason is that there is an extra quotation mark at the end of the third line of code “"”, After deleting , as follows
origin := c.Request.Header.Get("Origin")
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Access-Control-Allow-Headers", "Content-Type, AccessToken, X-CSRF-Token, Authorization, Token, x-token, x-user-id")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS,DELETE,PUT")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
Normal access .
边栏推荐
猜你喜欢

FTX US推出FTX Stocks,向主流金融行业迈进

2022年全球6家最具技术实力的的智能合约审计公司盘点

Shell programming specifications and variables

反射器中getattr,hasattr,delattr,setattr的使用

logging日志的封装

1. Install redis in CentOS 7

Cesium tutorial (1) interface introduction -3dfiles loading - change mouse operation settings

Addition, deletion, modification and query of the database at the terminal

DHCP principle and configuration

Iptables firewall, SNAT and DNAT
随机推荐
Webodm win10 installation tutorial (personal test)
系统安全与应用
What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!
阿里云短信验证第三方接口(快速使用)
LAMP--源码编译安装
磁盘管理与文件系统
改善宝宝过敏就吃伊敏舒,azg与Aibeca爱楽倍佳携手守护中国宝宝成长
Go语言学习
Joint query of database
网站服务器被攻击怎么办?向日葵提示防范漏洞是关键
Rsync remote synchronization
FTX US推出FTX Stocks,向主流金融行业迈进
When a subclass calls the constructor of its parent class
Establishment of FTP server
Some applications of std:: bind and std:: function
云原生运行环境搭建
Multimodal database | star ring technology multimode database argodb "one database for multiple purposes", building a high-performance Lake warehouse integrated platform
DHCP principle and configuration
Project training experience 1
FTX Foundation funded 15million to help covid-19 clinical trials, which will affect global public health