POST请求作为beego框架选项处理 [英] POST request treated as OPTIONS on beego framework
问题描述
我使用beego框架,在客户端上我的API框架和AngularJS。
我设置了所有CORS正确设置。我能做的GET请求。但是,当我尝试后,beego治疗是OPTIONS请求。它也抛出一个警告:多response.WriteHeader通话
。什么可能错了吗?
I'm using beego framework as my API framework and AngularJS on the client.
I have set all CORS setting correctly. I can do GET request. But, when i try to POST, beego treat is as OPTIONS request. It also throw a warning: multiple response.WriteHeader calls
. what could possibly wrong?
我beego CORS设置:
my beego CORS setting:
func init() {
orm.RegisterDataBase("default", "mysql", "root:@tcp(127.0.0.1:3306)/fakeapi")
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "DELETE", "PUT", "PATCH", "POST"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
}
我ANgularJS要求
My ANgularJS request
var transaction = $http.post(BASE_URL + "transaction", transactionData);
return $q.all([transaction]).then(function(response) {
console.log(response);
});
我的系统:
Ubuntu的14.04
beego:1.4.2
蜜蜂:1.2.4
angularJS:1.3.12
my system: Ubuntu 14.04 beego: 1.4.2 bee: 1.2.4 angularJS: 1.3.12
推荐答案
由于问题/ pull请求目前尚待要合并到主的可能:的问题912
That might because of an issue/pull request currently pending to be merged into master: issue 912
没有这一行,一切都很好:: router.go#L861
Without this line everything is fine:: router.go#L861
这似乎是符合提交3bb4d6f 这说明:
// Write status code if it has been set manually
// Set it to 0 afterwards to prevent "multiple response.WriteHeader calls"
(和 router.go
不要设置状态,因此错误消息)
(and router.go
do set a status, hence the error message)
提交f962457 的是应该解决这个问题,但还没有被合并。
Commit f962457 is supposed to solve this issue, but isn't merged yet.
另外问题904 提到自己无法检索会话数据$ P事$ pviously在会话引擎注册。
也许 Session.on标志可以提供帮助。
The other issue 904 mentions something about being unable to retrieve the Session data previously registered in the Session Engine. Maybe Session.on flag can help.
这篇关于POST请求作为beego框架选项处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!