0

I don’t have much knowledge about web and REST services, can be said beginner. Yesterday, I saw a term while wanting to retrieve information my website by the url. Using apirequest.io, when I try to send GET request to the url, the following error message is received.

Error: Request has been terminated
Possible causes: the network is offline, 
Origin is not allowed by Access-Control-Allow-Origin, 
the page is being unloaded, etc.

The point I don’t understand I simply send GET request. The API cannot access it with the request. Yet, a simple browser can read its content. What are the points I don’t know?

  • @mplungjan what about a browser? How does it access? – Soner from The Ottoman Empire Jul 11 '19 at 05:44
  • I for example get the same message here [SJFIDDLE](https://jsfiddle.net/mplungjan/qoyvkdp5/) `Access to XMLHttpRequest at 'https://soner.dev/test.txt' from origin 'https://fiddle.jshell.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.` – mplungjan Jul 11 '19 at 05:45
  • You control what you enter in the browser location bar. You do not control what requests the page you loaded does on your behalf. It is partly to protect you, partly to protect resources from being abused. For example I load "fakebookingsystem.com" and they try to make api calls to the backend of British Airways, presenting their data as their own. That is not great for you and not great for british airways so they are blocked. But if you load "registeredBAHandlingsite,co.uk" they ARE allowed to make api calls to ba.co.uk's backend – mplungjan Jul 11 '19 at 05:49
  • @mplungjan I mean a browser also does same type request(GET), how can a browser access to that data(website)? – Soner from The Ottoman Empire Jul 11 '19 at 05:49
  • It is the same as a popup window.If you click on a button that submits a form to _blank, you get a new tab, but if the script on the page does button.click, it can be blocked by the popup blocking because it was not user instigated – mplungjan Jul 11 '19 at 05:51
  • Please read some of the articles and dupes I posted. The browser is adhering to same origin when it loads a page you have typed in or a link you followed. The scripts that tries to get the page using xmlhttprequests and fails do not – mplungjan Jul 11 '19 at 05:59
  • 1
    @mplungjan Thank you so much your help, sir. I will. – Soner from The Ottoman Empire Jul 11 '19 at 06:22

0 Answers0