当前位置:网站首页>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)
边栏推荐
- CSDN always jumps to other positions when editing articles_ CSDN sends articles without moving the mouse
- 学习笔记5--高精地图解决方案
- How can PostgreSQL CDC set a separate incremental mode, debezium snapshot. mo
- Who is the "conscience" domestic brand?
- QT implements JSON parsing
- How do programmers live as they like?
- 九度 1480:最大上升子序列和(动态规划思想求最值)
- AtCoder Beginner Contest 258「ABCDEFG」
- 【Vite】1371- 手把手开发 Vite 插件
- "Everyday Mathematics" serial 58: February 27
猜你喜欢
非技術部門,如何參與 DevOps?
Learning Note 6 - satellite positioning technology (Part 1)
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
WorkManager學習一
非技术部门,如何参与 DevOps?
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
What is the most suitable book for programmers to engage in open source?
最全是一次I2C总结
Pseudo class elements -- before and after
@SerializedName注解使用
随机推荐
Ad20 make logo
AD20 制作 Logo
九度 1480:最大上升子序列和(动态规划思想求最值)
Flink CDC cannot monitor MySQL logs. Have you ever encountered this problem?
How can PostgreSQL CDC set a separate incremental mode, debezium snapshot. mo
字节跳动面试官:一张图片占据的内存大小是如何计算
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
How does redis implement multiple zones?
@JsonAdapter注解使用
Universal double button or single button pop-up
SAP UI5 ObjectPageLayout 控件使用方法分享
WorkManager的学习二
Have the bosses ever encountered such problems in the implementation of flinksql by Flink CDC mongdb?
SqlServer定时备份数据库和定时杀死数据库死锁解决
沟通的艺术III:看人之间 之倾听
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
Shortcut keys for vscode
ConstraintLayout的流式布局Flow
Who is the "conscience" domestic brand?
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?