Problems with CORS in application using API with Slim framework and Angularjs

Asked

Viewed 374 times

0

Good afternoon friends

I’m having trouble solving a problem

Requisição cross-origin bloqueada: A política de mesma origem (Same Origin Policy) impede a leitura do recurso remoto em http://api.dominio.com.br/exemplo. (Motivo: o cabeçalho CORS 'Access-Control-Allow-Origin' é incompatível com 'http://api.dominio.com.br').

I created a API using Slim to "feed" my application in Angularjs.

require "Slim/Slim.php";
require "CorsSlim/CorsSlim.php";

$app = new \Slim\Slim();

$corsOptions = array("origin" => "*", "allowMethods" => array("POST, GET, OPTIONS, PUT, DELETE"));

$cors = new \CorsSlim\CorsSlim($corsOptions);

$app->add($cors);
//e aqui vem as rotas
$app->run();

I did a search for Stackoverflow before opening this poll, and I contacted to see if my hosting was enabled CORS. How is a shared hosting the same and disabled. I would like a help to resolve this issue, I thank you in advance.

Response from Restclient:

Status Code: 200 OK
Access-Control-Allow-Headers: X-Authorization,X-Requested-With
Access-Control-Allow-Methods: POST,GET,DELETE,PUT,OPTIONS
Age: 0
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html
Date: Tue, 12 Jul 2016 00:03:56 GMT
Server: nginx/1.4.4
Transfer-Encoding: chunked
Vary: Accept-Encoding
Via: 1.1 varnish
X-Cacheable: YES
X-Varnish: 1680708969
access-control-allow-origin: *
magicmarker: 1
  • https://crossorigin.me/ ;)

  • thanks for the quick response... but this form of request only accepts GET. But thank you for your cooperation.

  • Did you ever test? It makes a GET request on your domain and returns what came.

  • I tried but it didn’t work because my API also has token validation there I think it made it difficult too.

  • i found this site but didn’t understand how to use http://enable-cors.org/index.html

  • I already had this problem I solved by adding the headers in the request: Access-Control-Allow-Origin. ;)

  • So Laerte the Slim is already doing it for min. $corsOptions

Show 2 more comments
No answers

Browser other questions tagged

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