This is my request header
Request URL:
Request Headers
Provisional headers are shown
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Origin:http://localhost:8000
Referer:http://localhost:8000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id:CACC0804-7333-424B-985E-DBA8164A45E1
this is the exact error which es on console
OPTIONS net::ERR_EMPTY_RESPONSE
When I try to access the same URL through postman it seems to work. This happens whenever I try to access different server.
Is there any particular way to make calls in angularJs, so that I can post request to any server with CORS enabled
This is my request header
Request URL:http://demo7876167.mockable.io/auth/login
Request Headers
Provisional headers are shown
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Origin:http://localhost:8000
Referer:http://localhost:8000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id:CACC0804-7333-424B-985E-DBA8164A45E1
this is the exact error which es on console
OPTIONS http://demo7876167.mockable.io/auth/login net::ERR_EMPTY_RESPONSE
When I try to access the same URL through postman it seems to work. This happens whenever I try to access different server.
Is there any particular way to make calls in angularJs, so that I can post request to any server with CORS enabled
Share Improve this question asked Jan 23, 2016 at 12:43 Abhishek JhaAbhishek Jha 9952 gold badges11 silver badges24 bronze badges 2- "When I try to access the same URL through postman it seems to work." — Are you really making that OPTIONS request with postman? – Quentin Commented Jan 23, 2016 at 12:47
- @Quentin sorry I meant the post call I am trying through postman – Abhishek Jha Commented Jan 23, 2016 at 13:16
1 Answer
Reset to default 3The browser is making a preflight OPTIONS request before making the POST request that you are expecting it to make. (Presumably it is the POST request you are testing with Postman).
The preflight request is required if you aren't making a simple request. By default Angular will encode the data in POST requests as JSON (instead of the more mon URL Form Encoding). JSON is not one of the acceptable content-types for a simple request.
The server you are making the request to must respond to the OPTIONS request to tell the browser that your JavaScript is allowed to make the JSON Encoded POST request that you are trying to make.
After the browser receives permission, it will make the POST request that you are simulating with Postman.
Alternatively, make a form encoded POST instead of a JSON encoded one.