I am hitting an open source API (to make an angular app) which has CORS enabled. I used chrome extension Allow-Control-Allow-Origin:* but only able to do GET requests. While doing POST, PUT and DELETE, the api call is done with OPTIONS and 404 error is coming. Please help.
Asked
Active
Viewed 272 times
0
-
you must have to handle OPTIONS. check this http://stackoverflow.com/questions/11926908/how-to-respond-to-an-http-options-request – gaurav bhavsar Apr 04 '17 at 05:42
-
Can it be configured on frontend ? @gauravbhavsar – Keshav Dhawan Apr 04 '17 at 05:50
-
"`which has CORS enabled`" as `OPTIONS` requests are failing, the API is clearly NOT configured for CORS correctly – Jaromanda X Apr 04 '17 at 05:55
-
It is always better to handle CORS on the backend. – Pritam Banerjee Apr 04 '17 at 06:02
-
agree with @Jaromanda, API is not configured to handle OPTIONS, its must be handle on server side. – gaurav bhavsar Apr 04 '17 at 06:02
1 Answers
0
Can you try to access you API with the custom headers as like sample given below,
var sampleAPI= {
method: 'POST',
url: sample-api,
data: youData,
headers: {
'Accept':'*/*',
'Content-Type':'application/json'
}
};
$http(sampleAPI).then(function (data) {
//some success result
}, function(data){
//some failure result
});

Immanuel Kirubaharan
- 1,094
- 1
- 11
- 17
-
Can you try to access you api with Advanced Rest Client extension of Chrome and check the response? – Immanuel Kirubaharan Apr 04 '17 at 12:40
-
It will work there as I tested the end point on postman also, but the problem arises once I make requests through browser on localhost. – Keshav Dhawan Apr 04 '17 at 12:55