Difficulty in accessing url with angular post

0

I'm passing a url and some data via angular post ... But the following warning appear on the chrome console:

  

Cross source requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Follow me code from the angle:

$http.post("localhost:8765/api/v1/users/oauth.json?token="+t1+"&redirect_url=localhost:8765/api/v1/users", data).success(function(responde){
            console.log(responde);
        });

What does this warning mean?

    
asked by anonymous 20.02.2017 / 17:16

2 answers

1

You are probably running this file without a local server using the file:\ protocol.

Additionally, in the excerpt:

$http.post("localhost:8765/api/v1/[...]

Angular is trying to infer the protocol based on its reference call, which translates as:

$http.post("file:\localhost:8765/api/v1/"[...]

As can be deduced from the error message, file:\ is not a supported protocol for CORS.

To solve the problem please serve the reference page via a local web server.

    
20.02.2017 / 17:44
0

There is a rule that is a page of the domain 'a.com.br' can not make requests in the domain 'b.com.br' this is basically a security rule to avoid using the exclusive services of an application in another location.

I suppose you have 2 servers one for the angled project * (with the html, js, css ...) and another one of the backend (in the php case)

In this case the php server must be configured to enable cross orign.

I found this link that can help you link

No php:

<?php
header("Access-Control-Allow-Origin: *");
?>

* (very careful when using header in php)

    
20.02.2017 / 17:35