当前位置:网站首页>beego跨域问题解决方案-亲试成功
beego跨域问题解决方案-亲试成功
2022-07-05 10:18:00 【lookNo施】
filter.go
var success = []byte("SUPPORT OPTIONS")
var corsFunc = func(ctx *context.Context) {
origin := ctx.Input.Header("Origin")
ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH")
ctx.Output.Header("Access-Control-Max-Age", "3600")
ctx.Output.Header("Access-Control-Allow-Headers", "X-Custom-Header,accept,Content-Type,Access-Token")
ctx.Output.Header("Access-Control-Allow-Credentials", "true")
ctx.Output.Header("Access-Control-Allow-Origin", origin)
if ctx.Input.Method() == http.MethodOptions {
// options请求,返回200
ctx.Output.SetStatus(http.StatusOK)
_ = ctx.Output.Body(success)
}
}
func init() {
beego.InsertFilter("/*", beego.BeforeRouter, corsFunc)
}
在app.conf中添加
copyrequestbody = true
POST数据在this.Ctx.Input.RequestBody中获取
var num1 map[string]interface{
}
err := json.Unmarshal(this.Ctx.Input.RequestBody,&num1)
边栏推荐
- How can non-technical departments participate in Devops?
- Comparative learning in the period of "arms race"
- AtCoder Beginner Contest 258「ABCDEFG」
- Go项目实战—参数绑定,类型转换
- 《剑来》语句摘录(七)
- pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
- 【黑马早报】罗永浩回应调侃东方甄选;董卿丈夫密春雷被执行超7亿;吉利正式收购魅族;华为发布问界M7;豆瓣为周杰伦专辑提前开分道歉...
- 【SWT组件】内容滚动组件 ScrolledComposite
- vscode的快捷键
- Click the picture in the mobile browser and the picture will not pop up
猜你喜欢
Secteur non technique, comment participer à devops?
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
How do programmers live as they like?
非技术部门,如何参与 DevOps?
学习笔记5--高精地图解决方案
伪类元素--before和after
【Vite】1371- 手把手开发 Vite 插件
手机厂商“互卷”之年:“机海战术”失灵,“慢节奏”打法崛起
Pseudo class elements -- before and after
Workmanager learning 1
随机推荐
如何写出高质量的代码?
IDEA新建sprintboot项目
php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
Learning Note 6 - satellite positioning technology (Part 1)
学习笔记4--高精度地图关键技术(下)
Secteur non technique, comment participer à devops?
How can PostgreSQL CDC set a separate incremental mode, debezium snapshot. mo
《微信小程序-基础篇》小程序中的事件与冒泡
In the year of "mutual entanglement" of mobile phone manufacturers, the "machine sea tactics" failed, and the "slow pace" playing method rose
@Jsonadapter annotation usage
Interview: is bitmap pixel memory allocated in heap memory or native
Implementation of wechat applet bottom loading and pull-down refresh
How to judge that the thread pool has completed all tasks?
StaticLayout的使用详解
字节跳动面试官:一张图片占据的内存大小是如何计算
How to write high-quality code?
Learning notes 5 - high precision map solution
QT implements JSON parsing
How did automated specification inspection software develop?
How do programmers live as they like?