Request being Barred by CORS policy

Asked

Viewed 554 times

0

I’m trying to build my Front End using the Icinga API, but I’m constantly encountering the following error:

Access to Xmlhttprequest at 'http://icinga.ultraip.com.br/cgi-bin/icinga/status.cgi?search_string=&jsonoutput' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested Resource.

I’ve tried everything, I’ve seen every possible tutorial on the Internet and I couldn’t. But what makes me more curious, is that I can make this same request for Postman, without any difficulty.

Remembering that:

  1. I am making request for an API that has Basic Auth, the login and password, I am passing in Header, encrypted but without success.
  2. The same thing being done in Postman, no error returns, quite the contrary, I went through without any headache.

Now, my doubts focus on the following: How Postman does this and whether there is a possibility that I can see the requisition that was made by Postman, so I can copy it.

$.ajax({
    url: "url",
    crossDomain: true,
    data: "",
    dataType: 'json',
    success: function (data) {
        console.log(data);
    },
    type: 'GET'
});
  • The browser will block because the API does not have the header Access-Control-Allow-Origin. One way to circumvent this is by using a language back-end, for example: PHP.

  • So who is doing this, is my Browser?

  • 1

    Yes. It’s the browser that blocks.

  • Would you know where to put this?

  • That?? Don’t get it.

  • Access-Control-Allow-Origin

  • I tried to put it on Apache2.conf but it didn’t roll

  • It is necessary to add the header on the website ultraip.com.br

  • Got it. You could tell me what the name of the file would be?

  • https://enable-cors.org/server_apache.html

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.