the accountant
the accountant

Reputation: 526

can I make the browser ignore the (CORS) rules?

I want a simple javascript script that exists on my localhost to make a connection to another domain(eg: anotherdomain.com) with ajax and get the response , but all my browsers tell me that error of (connection blocked , Reason: CORS header 'Access-Control-Allow-Origin' missing)

but when I check the network traffic with network monitor program like (fiddler), I see that the response already came from the server at (anotherdomain.com) to my local machine , it is just my browser who is blocking me from getting it !!

1- can I order my browser to ignore the CORS rules using javascript code?

2- what is my options to overcome this problem? is building a custom client disktop application with c# to send and receive requests freely is the best way to do it?

3- is CORS policy designed to protect the web clients or the web servers ?

thank you, and please consider that I'm complete newbie in web

Upvotes: 3

Views: 13934

Answers (1)

Jakub Rożek
Jakub Rożek

Reputation: 2130

but when I check the network traffic with network monitor program like (fiddler), I see that the response already came from the server at (anotherdomain.com) to my local machine , it is just my browser who is blocking me from getting it !!

Well for sure, the connection was estabilished to check the presence of the header you mentioned, but data was unlikely to be transferred.

Regarding your questions,

  1. There are 2 options actually. One is to set the Access-Control-Allow-Origin header with proper origin according to yours. The second is to make a JSONP call, though the response of server must support such a solution.

  2. The best option is to have a server with the above header specified. Your server would handle all the network stuff on its side and your script would just get/send some responses/requests.

  3. I would say it designed more to protect the server. Imagine the following situations. Your script on your site makes a lot of POST requests to the another site. Actions like submitting forms etc. could happen and would be allowed. That's harmful, right? You can read about that in this stack question.

Upvotes: 1

Related Questions