我在客户端使用 beego 框架作为我的 API 框架和 AngularJS。
我已正确设置所有 CORS 设置。我可以做 GET 请求。但是,当我尝试发布时,beego treat 是作为 OPTIONS 请求。它还会引发警告:multiple response.WriteHeader calls
。可能有什么问题?
我的 beego CORS 设置:
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 请求
var transaction = $http.post(BASE_URL + "transaction", transactionData);
return $q.all([transaction]).then(function(response) {
console.log(response);
});
我的系统: Ubuntu 14.04 蜜蜂:1.4.2 蜜蜂:1.2.4 angularJS:1.3.12
最佳答案
这可能是因为当前有待合并到 master 中的问题/拉取请求:issue 912
Without this line everything is fine:: router.go#L861
这似乎符合commit 3bb4d6f显示:
// Write status code if it has been set manually
// Set it to 0 afterwards to prevent "multiple response.WriteHeader calls"
(和 router.go
设置状态,因此错误消息)
Commit f962457应该解决此问题,但尚未合并。
其他issue 904提到无法检索先前在 session 引擎中注册的 session 数据。 也许Session.on flag可以提供帮助。
关于javascript - POST 请求在 beego 框架上被视为 OPTIONS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28337387/