0

I am trying to request server via HTTPS POST method in ionic. But some of reason, it failed every time. I don't know why this happened? Are there any correct way?

$http({
          url: "https://beta.test.com/auth/authenticate/",
          method: "POST",
          data: {userName: "xxx", password: "xxx", ipAddress: "xxx", remeberMe: true},
          headers: {'Content-Type': 'application/json'}
      }).success(function (res) {
              $scope.persons = res; // assign  $scope.persons here as promise is resolved here
          }).error(function (res) {
              $scope.status = status;
          });
Michael Lee
  • 135
  • 1
  • 11

2 Answers2

2

It looks like your code in the success function should be $scope.persons = res.data.

Mike Feltman
  • 5,160
  • 1
  • 17
  • 38
  • Thanks for your help. But what I want to know it that how to request to HTTPS via Post method in ionic app. Would you like to help me? – Michael Lee May 05 '16 at 20:23
  • What's failing? Is your success method or your error method being called?(BTW, success and error are deprecated.) – Mike Feltman May 05 '16 at 20:30
  • The error is XMLHttpRequest cannot load `https://beta.test.com/auth/authenticate/`. Response for preflight has invalid HTTP status code 404 – Michael Lee May 05 '16 at 20:35
  • Looks like it's actually a CORS issue. Check out the answer to this question: http://stackoverflow.com/questions/33660712/angularjs-post-fails-response-for-preflight-has-invalid-http-status-code-404 – Mike Feltman May 05 '16 at 20:47
  • This is a longshot, but probably still an issue anyway. rememberMe is spelled wrong in your data parameter. Do you have a debugging environment on the server? I would first try to trace the code on the server and see if it's reaching that point. If you find something in the code, that should give you direction. If it's not getting to your code at all, it's probably a configuration issue on your server. – Mike Feltman May 05 '16 at 20:55
  • Also, check this one out if you're using Chrome. I dealt with something similar a while back and only ended up suspecting the Browser when I happened to try the page in ie on a whim.http://stackoverflow.com/questions/33660712/angularjs-post-fails-response-for-preflight-has-invalid-http-status-code-404 – Mike Feltman May 05 '16 at 21:01
0

It should be like this

  $scope.persons = res.data; 

but check in console that you will getting proper response

Wasiq Muhammad
  • 3,080
  • 3
  • 16
  • 29