We have recently created an easy API call, then the error response to preflight request doesn’t pass access control check: No “Access-Control-Allow-Origin” header is present on the requested resource. Here is our answer to solve this error.
response to preflight request doesn't pass access control check: No "Access-Control-Allow-Origin" header is present on the requested resource
How To Solve It?
To solve this issue, for Windows, disable the CORS. Click the Start button, then select “Run” or press Windows + R. Carry out the following order: “chrome.exe –user-data-dir= “C://Chrome dev session” –disable-web-security”.
How Does It Happen?
While we are doing a basic API request, the following error appears.
“XMLHttpRequest cannot load http://server.apiurl.com:8000/u/login?login=facebook. Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. The origin ‘http://localhost’ is therefore not allowed access. Error 405″.
How To Fix response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource error
Solution 1
With Windows:
- Launch the Menu
- Click “Run” or press Windows+R
- Run the following code: “chrome.exe –user-data-dir=”C://Chrome dev session” –disable-web-security”
With Mac:
- Head to the Terminal
- Carry out the following instruction: “open /Applications/Google\ Chrome.app –args –user-data-dir=”/var/tmp/Chrome dev session” –disable-web-security”
Solution 2
Because the “API Server” is considered a PHP program, the method listed below worked quite well. Insert the lines into index.php.
“header(‘Access-Control-Allow-Origin: *’);
header(‘Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS’);
header(‘Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token’)”.
Solution 3
There is no reason to close any Chrome in the version when its first successful solution has been used and the today version for Windows running Chrome.
- Make a shortcut for it on the desktop.
- Select the icon and select Properties from the menu that appears.
- Modify the Target field.
- Change the document address to “C:\Program Files (x86)\Google\Chrome\Application\chrome.exe –disable-web-security –user-data-dir=”C:/ChromeDevSession”.
- Launch Chrome and dismiss the warning that says “–disable-web-security not available!”
Please be aware that using this specific browser instance can expose you to hackers, so you should be careful!
Conclusion
Wrapping up our instruction for solving the response to preflight request doesn’t pass access control check: No “Access-Control-Allow-Origin” header is present on the requested resource error. Hope you are satisfied with our answer.
Go ahead and type your questions in the comment section if you have any. While you are reading our article, if there are any better solutions, please send us your ideas and thoughts to provide better ways to resolve these problems. Thank you!
Related posts
- Top Ways To Create A User-Friendly Online Property Search For Your Real Estate Clients
If you’re running a real estate business, you’re well aware that pretty much most of the paperwork has become automated and it’s time for you really get an education on what you need to use in terms of technology. This is important to make your online presence and services stand out from the competition. Like […]
- List Education Websites for Students, providing a variety of materials and completely free
Everyone would like to get the highest quality of education in order to fulfill their goals. But the more an institution is of high quality and reputable, the more fees they charge. Students typically leave their education in a state of nil and work blue collar jobs to achieve their primary needs. Additionally, they collect […]
- Simple solution to correct the requests.exceptions.ConnectionError: (‘Connection aborted.’ RemoteDisconnected(‘Remote end closed connection without response’)) issue
Python is a popular programming language that can be used widely in a lot of applications. Python is also a good choice as a programming language depending on user background and perspective. Because it is used widely and popular, if you find any errors when using Python. It is a common problem, you face the […]
- “[Errno 61] Connection refused” is occurring even, the program is connecting with the port well and the socket is running in the interfaces.
If you see the “[Errno 61] Connection refused” issue although you checked the program, port, socket and interfaces. Although your program of Python works well in the server and the client, they are installed at the same device. The local IP from my device is connecting with the clients but this IP is not connected […]
- Description “Return by Reference”.
C++ is considered not only as a language of Object Oriented Programming, but also an intermediate level language. It identifies both high and low level languages. It became easy and widely used in computer programs and that is the reason why we should understand the definition and its function as well. Such as Return by […]