0
votes

We have front end using Angularjs and we hit apis to get details from another domain which uses apache server and another domain as nodejs server.

Whilc hitting api for both servers , in some mac machines the apis failed in OPTIONS request itself. I don't understand why its happens for some machines alone.

In the initial call it shows failed while inspecting in browser , also type is xhr method.

Can someone help on this why we facing such issues.

Systems working fine have request headers as

Request Headers view source Accept:/ Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Access-Control-Request-Headers:accept, content-type Access-Control-Request-Method:POST Connection:keep-alive Host:XXX.XXXXX.com Origin:http://localhost Referer:http://localhost/XXXXX/ User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36 [7/15/2015 8:20:06 PM] karthick raja: it shows this request header

We get response in success machine

but the failed systems has

Request Headers Access-Control-Request-Headers:accept, content-type Access-Control-Request-Method:POST Host:xxxx.xxxx.xom Origin:http://localhost Referer:http://localhost/XXXXXX/ User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36

In failed machines the service gets failed

1
get more help by providing all the response headers, otherwise it's a big guessing game. Any limit restrictions on api?charlietfl

1 Answers

1
votes

Some browser placing preflighted request for your post request because Content-type seems to be empty in your request header. Please set content type to one from the below:

  • application/x-www-form-urlencoded
  • multipart/form-data
  • text/plain

Other than above Content-type's set to request header, browsers place a preflighted request for post method.

To know more about "Preflighted requests" please check the below link for better idea. https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests