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

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

    The only thin you have to change is to use property "params" rather than "data" when you create your $http object:

    $http({
       method: 'POST',
       url: serviceUrl + '/ClientUpdate',
       params: { LangUserId: userId, clientJSON: clients[i] },
    })
    

    In the example above clients[i] is just JSON object (not serialized in any way). If you use "params" rather than "data" angular will serialize the object for you using $httpParamSerializer: https://docs.angularjs.org/api/ng/service/$httpParamSerializer

提交回复
热议问题