0

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? Commented Jul 15, 2015 at 15:12

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Shall we add more than one content type like application/json,text/plain
No, you cant use multiple content type for one request. add one from three content type listed above to avoid preflighted request or make sure server respond for option method
How and where can i set the content-type in angularjs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.