当前位置:网站首页>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)
边栏推荐
- 驱动制造业产业升级新思路的领域知识网络,什么来头?
- Learning II of workmanager
- > Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
- In the year of "mutual entanglement" of mobile phone manufacturers, the "machine sea tactics" failed, and the "slow pace" playing method rose
- Lepton 无损压缩原理及性能分析
- The most complete is an I2C summary
- 5g NR system architecture
- 最全是一次I2C总结
- 想请教一下,十大券商有哪些?在线开户是安全么?
- [observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
猜你喜欢

How to write high-quality code?

StaticLayout的使用详解

如何判断线程池已经执行完所有任务了?

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

@Serializedname annotation use

AtCoder Beginner Contest 258「ABCDEFG」

In the year of "mutual entanglement" of mobile phone manufacturers, the "machine sea tactics" failed, and the "slow pace" playing method rose

Swift tableview style (I) system basic

驱动制造业产业升级新思路的领域知识网络,什么来头?

一个程序员的职业生涯到底该怎么规划?
随机推荐
LDAP概述
Learning II of workmanager
C语言实现QQ聊天室小项目 [完整源码]
vscode的快捷键
非技术部门,如何参与 DevOps?
Ad20 make logo
leetcode:1200. 最小绝对差
Comparative learning in the period of "arms race"
AtCoder Beginner Contest 258「ABCDEFG」
学习笔记6--卫星定位技术(上)
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
[vite] 1371 - develop vite plug-ins by hand
“军备竞赛”时期的对比学习
[可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename……
In wechat applet, after jumping from one page to another, I found that the page scrolled synchronously after returning
[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
Usage differences between isempty and isblank
Flink CDC cannot monitor MySQL logs. Have you ever encountered this problem?
微信小程序触底加载与下拉刷新的实现
面试:List 如何根据对象的属性去重?