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:
- I am making request for an API that has Basic Auth, the login and password, I am passing in Header, encrypted but without success.
- 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.– Valdeir Psr
So who is doing this, is my Browser?
– Fernando Campanate
Yes. It’s the browser that blocks.
– Valdeir Psr
Would you know where to put this?
– Fernando Campanate
That?? Don’t get it.
– Valdeir Psr
Access-Control-Allow-Origin
– Fernando Campanate
I tried to put it on Apache2.conf but it didn’t roll
– Fernando Campanate
It is necessary to add the header on the website
ultraip.com.br
– Valdeir Psr
Got it. You could tell me what the name of the file would be?
– Fernando Campanate
https://enable-cors.org/server_apache.html
– Valdeir Psr