How can I post data as form data instead of a request payload?

前端 未结 22 2226
庸人自扰
庸人自扰 2020-11-22 00:13

In the code below, the AngularJS $http method calls the URL, and submits the xsrf object as a \"Request Payload\" (as described in the Chrome debugger network t

22条回答
  •  粉色の甜心
    2020-11-22 00:45

    You can define the behavior globally:

    $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
    

    So you don't have to redefine it every time:

    $http.post("/handle/post", {
        foo: "FOO",
        bar: "BAR"
    }).success(function (data, status, headers, config) {
        // TODO
    }).error(function (data, status, headers, config) {
        // TODO
    });
    

提交回复
热议问题