Good morning. I'm creating an API to make a service available to other applications. I have the following scenario. A system to make the service available. This system has a virtualhost configured. The uri is link . When accessing this url, internally using get - the case I have already tested at least - it prints the message on the screen.
$this->app->get("/", function () {
$header = get_headers('http://www.meuservico.com.br', 1);
$receive = $header['Content-Type'][0];
$arr_receive = split(";", $receive);
echo $arr_receive[0];
});
I created an external project and it runs on localhost too, but does not have a virtualhost set. Here's the code for external access.
$(function() {
$.ajax({
contentType: "application/json",
url: 'http://meuservico.com.br/lib/api/api.php',
data: { name: 'norm' },
// dataType: "json",
success: function(data){
console.log(data);
},
error: function (request) {
console.log(request);
}
});
});
In this case, I get the following error.
XMLHttpRequest cannot load http://meuservico.com.br/lib/api/api.php?name=norm. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://www.e-sms.com.br' that is not equal to the supplied origin. Origin 'http://localhost' is therefore not allowed access.