当前位置:网站首页>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)
边栏推荐
- PHP solves the problems of cache avalanche, cache penetration and cache breakdown of redis
- [论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
- 学习笔记4--高精度地图关键技术(下)
- Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
- 橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布
- 风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
- @Serializedname annotation use
- SAP ui5 objectpagelayout control usage sharing
- dsPIC33EP 时钟初始化程序
- 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
猜你喜欢

> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
![[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems](/img/6c/5b14f47503033bc2c85a259a968d94.png)
[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems

风控模型启用前的最后一道工序,80%的童鞋在这都踩坑

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

《天天数学》连载58:二月二十七日

Learning II of workmanager

What is the most suitable book for programmers to engage in open source?

Constraintlayout officially provides rounded imagefilterview

Universal double button or single button pop-up

ModuleNotFoundError: No module named ‘scrapy‘ 终极解决方式
随机推荐
[JS] array dimensionality reduction
SqlServer定时备份数据库和定时杀死数据库死锁解决
【SWT组件】内容滚动组件 ScrolledComposite
How to plan the career of a programmer?
flex4 和 flex3 combox 下拉框长度的解决办法
NAS与SAN
leetcode:1200. 最小绝对差
伪类元素--before和after
How do programmers live as they like?
Glide Mastery
How to judge that the thread pool has completed all tasks?
Pseudo class elements -- before and after
Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
WorkManager学习一
橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布
LiveData 面试题库、解答---LiveData 面试 7 连问~
一个可以兼容各种数据库事务的使用范例
Learning II of workmanager
Constraintlayout officially provides rounded imagefilterview
SQL Server 监控统计阻塞脚本信息