0
Good morning. I am creating an API to provide a service for other applications. I have the following scenario. A system to provide the service. This system has a virtualhost configured. The Uri is http://meuservico.com.br/lib/api/api.php. When accessing this url, internally using get - the case I’ve 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 this scrolls on localhost as well, but it does not have a virtualhost defined. Follow 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 that 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.