0

I am trying to post data to a web service but the data is missing.

Here is the code

        var product = {
          CategoryID: 'test'
        };

        $http({
          url: URL,
          method: "POST",
          data: product,
          headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        })
        .success(function(data,status,headers,config) {
          console.log(data);
        })
        .error(function(data,status,headers,config) {
          console.log(data);
        });

The POST data on the server is empty.

I have set up Access-Control-Allow-Origin,Access-Control-Allow-MethodAccess-Control-Allow-Headerss and Access-Control-Allow-Headers on the server.

This API works fine when tested through Postman

SunMan
  • 169
  • 2
  • 14
  • You your browser debugger to see what is actually sent and compare that to what is sent using Postman. There is obviously a difference somewhere but you will have to be the one that finds it. – Igor Nov 11 '16 at 17:21
  • @Igor I have and there does not appear to be a difference. The ionic app even has a Content-Length that is non zero. – SunMan Nov 11 '16 at 17:35
  • can you tell us more about how you retrieve data on the server side ? – erwan Nov 11 '16 at 17:42
  • Possible duplicate of [AngularJs $http.post() does not send data](http://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-data) – erwan Nov 11 '16 at 17:46
  • Possible duplicate of [How do I POST urlencoded form data with $http in AngularJS?](http://stackoverflow.com/questions/24710503/how-do-i-post-urlencoded-form-data-with-http-in-angularjs). Encode the data with the [$httpParamSerializer service](https://code.angularjs.org/1.4.1/docs/api/ng/service/$httpParamSerializer) – georgeawg Nov 11 '16 at 22:04

1 Answers1

0

For your issue try a look at this one How do I POST urlencoded form data with $http in AngularJS? - you probably need to transform your request in order to sent in via $http service with the required content type.

Community
  • 1
  • 1
k10der
  • 716
  • 1
  • 10
  • 15