当前位置:网站首页>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)
边栏推荐
- 报错:Module not found: Error: Can‘t resolve ‘XXX‘ in ‘XXXX‘
- QT implements JSON parsing
- How to plan the career of a programmer?
- The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five
- php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
- 5g NR system architecture
- 想请教一下,十大券商有哪些?在线开户是安全么?
- 一个程序员的职业生涯到底该怎么规划?
- Glide conclusion
- Lepton 无损压缩原理及性能分析
猜你喜欢

Uni app running to wechat development tool cannot Preview

Have you learned to make money in Dingding, enterprise micro and Feishu?

Window下线程与线程同步总结

Swift tableview style (I) system basic

字节跳动面试官:一张图片占据的内存大小是如何计算

How to judge that the thread pool has completed all tasks?

学习笔记4--高精度地图关键技术(下)

pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)

Timed disappearance pop-up

Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
随机推荐
ModuleNotFoundError: No module named ‘scrapy‘ 终极解决方式
IDEA新建sprintboot项目
Constraintlayout officially provides rounded imagefilterview
非技術部門,如何參與 DevOps?
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
Completion report of communication software development and Application
Pseudo class elements -- before and after
《天天数学》连载58:二月二十七日
ConstraintLayout官方提供圆角ImageFilterView
DDOS攻击原理,被ddos攻击的现象
Coneroller执行时候的-26374及-26377错误
Activity jump encapsulation
Who is the "conscience" domestic brand?
Golang应用专题 - channel
ConstraintLayout的流式布局Flow
StaticLayout的使用详解
钉钉、企微、飞书学会赚钱了吗?
想请教一下,十大券商有哪些?在线开户是安全么?
请问大佬们 有遇到过flink cdc mongdb 执行flinksql 遇到这样的问题的么?
@Jsonadapter annotation usage