当前位置:网站首页>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)
边栏推荐
- C language QQ chat room small project [complete source code]
- [论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
- Have you learned to make money in Dingding, enterprise micro and Feishu?
- 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
- The most complete is an I2C summary
- Workmanager Learning one
- 【Vite】1371- 手把手开发 Vite 插件
- GO项目实战 — Gorm格式化时间字段
- ConstraintLayout的流式布局Flow
- Have the bosses ever encountered such problems in the implementation of flinksql by Flink CDC mongdb?
猜你喜欢
Window下线程与线程同步总结
一个程序员的职业生涯到底该怎么规划?
[dark horse morning post] Luo Yonghao responded to ridicule Oriental selection; Dong Qing's husband Mi Chunlei was executed for more than 700million; Geely officially acquired Meizu; Huawei releases M
ConstraintLayout的流式布局Flow
《天天数学》连载58:二月二十七日
How to judge that the thread pool has completed all tasks?
@Serializedname annotation use
ConstraintLayout官方提供圆角ImageFilterView
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
mongoDB副本集
随机推荐
风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
Have you learned to make money in Dingding, enterprise micro and Feishu?
In wechat applet, after jumping from one page to another, I found that the page scrolled synchronously after returning
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
App各大应用商店/应用市场网址汇总
小程序中自定义行内左滑按钮,类似于qq和wx消息界面那种
Node の MongoDB Driver
Click the picture in the mobile browser and the picture will not pop up
《剑来》语句摘录(七)
Universal double button or single button pop-up
Pseudo class elements -- before and after
ByteDance Interviewer: how to calculate the memory size occupied by a picture
PHP solves the problems of cache avalanche, cache penetration and cache breakdown of redis
Learning notes 5 - high precision map solution
伪类元素--before和after
学习笔记4--高精度地图关键技术(下)
@Serializedname annotation use
Zblogphp breadcrumb navigation code
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
一个可以兼容各种数据库事务的使用范例