I am trying to send a POST
request to a server that only accepts x-www-form-urlencoded
data.
When I test this on Postman, it works. For example, the preview title looks like this:
POST /api/signin HTTP/1.1 Host: myproj.herokuapp.com Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded email=joe%40gmail.com&password=1234567
However, when I launch it from my application, the title viewed in the Chrome console looks like this:
Remote Address:10.10.10.250:80 Request URL:http://myproj.herokuapp.com/api/signIn Request Method:POST Status Code:400 Bad Request Request Headersview source Accept:application/json, text/plain, */* Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.8 Connection:keep-alive Content-Length:53 Content-Type:application/x-www-form-urlencoded; charset=UTF-8 Host:rapidit.herokuapp.com Origin:http://localhost Referer:http://localhost/rapid/v3/src/app/index/ User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Form Dataview parsed {"email":" joe@gmail.com ","password":"1234567"}
Obviously, it is not sending data in the correct format.
Here's what it looks like in my Angular factory (with hard-coded input data):
var LoginResource = $resource("http://myproj.herokuapp.com/api/signIn", {}, { post: { method: "POST", isArray: false, headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'} } }); var loginUser = function (){ return LoginResource.post( { email: " joe@gmail.com ", password: "1234567" } ).$promise;
How can I get the data in POST in the required format?
source share