Reputation: 47431
I am performing a post to a backend server which is an openid authentication library. It works when I have a simple form with its action pointing to the server url.
However it fails when I use the $http.post method. I have compared the headers and changed the content-type to url-form encoded. This resolves part of the problem, but the redirection from the server still fails.
Any ideas on what are the differences between a regular form post and angular's $http.post which is causing this behavour ?
Upvotes: 4
Views: 2627
Reputation: 3118
but the redirection from the server still fails.
Server redirection is not supposed to work back into front end because the ajax request will give you the http status code of it's final page reached. So if the page you request by ajax is redirecting to another page, it will give you 200 status. You can read the w3c draft for this http://www.w3.org/TR/XMLHttpRequest/#infrastructure-for-the-send-method .
Upvotes: 2
Reputation: 108491
If you really wanted to see the difference I would recommend setting up a free tool like Fiddler. Then you can see the requests as they leave and/or arrive and look at every difference.
But, theoretically, there are only whatever differences you have set up in your form tag or your $http.post call. They're both using POST I assume. One might be using a different content-type (enctype on a form tag) than the other though... like "multipart/form-data" or "application/x-www-form-urlencoded" versus "application/json"... that's a critical piece that tells the server what type of data you're sending. And if the server is expecting one type and getting the other, that might account for your failure.
It's hard to say without seeing your code though.
Upvotes: 1