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 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式