duanke1984 2015-02-05 06:16
浏览 289
已采纳

POST请求在beego框架上被视为OPTIONS

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?

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,
    }))

}

My ANgularJS request

var transaction = $http.post(BASE_URL + "transaction", transactionData);
                return $q.all([transaction]).then(function(response) {
            console.log(response);
        });

my system: Ubuntu 14.04 beego: 1.4.2 bee: 1.2.4 angularJS: 1.3.12

  • 写回答

2条回答 默认 最新

  • duanluo5096 2015-02-05 06:54
    关注

    That might because of an issue/pull request currently pending to be merged into master: issue 912

    Without this line everything is fine:: router.go#L861

    That seems to be in line with commit 3bb4d6f which shows:

    // Write status code if it has been set manually
    // Set it to 0 afterwards to prevent "multiple response.WriteHeader calls"
    

    (and router.go do set a status, hence the error message)

    Commit f962457 is supposed to solve this issue, but isn't merged yet.


    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料