当前位置:网站首页>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 .
边栏推荐
- ES6新特性(入门)
- Remote access and control
- darknet-yolov3、yolo-fastect使用rtx30系显卡cuda环境在win10平台编译与训练的相关问题
- Function call of shell script
- Linu performance tuning: how can we alleviate the situation in the face of DDoS attacks?
- Shell script delete automatically clean up files that exceed the size
- Shell -- custom variables and assignments
- According to SQL, you must know and learn SQL (MySQL)
- Using markdowm
- FTX 基金会资助1500万帮助新冠疫苗临床实验,将影响全球公共卫生
猜你喜欢

LVM与磁盘配额

Array and subscript index

Source code compilation and installation LNMP and discuz Forum

torch加载自定义模型的问题

多模态数据库 | 星环科技多模数据库ArgoDB“一库多用“,构建高性能湖仓集一体平台

shell--变量的运算

Ftx.us launched stock and ETF trading services to make trading more transparent

Shell programming specifications and variables

面试常问的问题总结【呕心沥血熬了一个晚上总结的】

Pruning - quantification - turn to onnx Chinese series tutorials
随机推荐
LAMP--源码编译安装
Soul submitted an application for listing in Hong Kong stocks, accelerating the diversified and scene based layout of social gathering places
关于testng相关标签的使用
Using markdowm
Shell script backup MySQL database
账号管理与权限
If conditional statement of shell
Establishment of FTP server
Stress performance test of website based on AB tool under Apache
PXE高效批量网络装机
KVM command set management virtual machine
1. CentOS 7 安装 redis
Source code compilation and installation lamp and discuz Forum
备忘录 @RestControllerAdvice与异常拦截类示例
PSI|CSI和ROC|AUC和KS -备忘录
iptables防火墙
项目实训经历1
When a subclass calls the constructor of its parent class
面试常问的问题总结【呕心沥血熬了一个晚上总结的】
ESXI虚拟机启动,模块“MonitorLoop”打开电源失败