当前位置:网站首页>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)
边栏推荐
猜你喜欢
【观察】跨境电商“独立站”模式崛起,如何抓住下一个红利爆发时代?
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
Workmanager Learning one
How did automated specification inspection software develop?
Uni app running to wechat development tool cannot Preview
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
Solution of ellipsis when pytorch outputs tensor (output tensor completely)
伪类元素--before和after
The most complete is an I2C summary
随机推荐
Learning II of workmanager
Usage differences between isempty and isblank
uniapp + uniCloud+unipay 实现微信小程序支付功能
如何判断线程池已经执行完所有任务了?
WorkManager的学习二
[paper reading] kgat: knowledge graph attention network for recommendation
Go项目实战—参数绑定,类型转换
【黑马早报】罗永浩回应调侃东方甄选;董卿丈夫密春雷被执行超7亿;吉利正式收购魅族;华为发布问界M7;豆瓣为周杰伦专辑提前开分道歉...
“军备竞赛”时期的对比学习
面试:Bitmap像素内存分配在堆内存还是在native中
LDAP概述
Swift tableview style (I) system basic
到底谁才是“良心”国产品牌?
Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
Lepton 无损压缩原理及性能分析
[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems
The most complete is an I2C summary
C语言实现QQ聊天室小项目 [完整源码]
What is the most suitable book for programmers to engage in open source?
GO项目实战 — Gorm格式化时间字段