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

前端 未结 22 2227
庸人自扰
庸人自扰 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:53

    In your app config -

    $httpProvider.defaults.transformRequest = function (data) {
            if (data === undefined)
                return data;
            var clonedData = $.extend(true, {}, data);
            for (var property in clonedData)
                if (property.substr(0, 1) == '$')
                    delete clonedData[property];
    
            return $.param(clonedData);
        };
    

    With your resource request -

     headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
    

提交回复
热议问题