Error 'No' Access-Control-Allow-Origin 'header is present on the requested resource "when consuming a REST API service with the POST method in AngularJS

1

I am consuming a REST API service with AngularJS and the POST method, when consuming the service, the following error is coming up:

  

XMLHttpRequest can not load https: // ..... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin link is therefore not allowed access.

I have already read and it is obviously a problem of CORS since when sending the request and the server answers, the Access-Control-Allow-Origin header must contain in this case my IP (or the ip of the angularjs application) or it must contain something like Access-Control-Allow-Origin="*" .

Already check in the browser and effectively the answer sent to me by the server does not contain the Access-Control-Allow-Origin="*" , as seen in the following image:

The obvious solution is to configure in the server where the REST services are the header Access-Control-Allow-Origin but unfortunately this is a server from an external provider where it has not been easy to make the change.

I want to know if there is any way in AngularJS that allows me to solve this problem in the client and not continue waiting for me to make the change in the server.

    
asked by Ivan Dario Duque M. 26.06.2017 в 20:37
source

3 answers

3

In Chrome, install this extension Allow-Control-Allow-Origin You activate it and you can allow connections between domains.

    
answered by 04.07.2017 в 18:15
-1

Nothing easier in your php server-side at the beginning of <?php ob_start() ;

Your content and at the end

 header('Content-type: application/json');
        header("Access-Control-Allow-Origin: *");
        ob_end_flush();

?>

That's it.

    
answered by 17.12.2017 в 01:19
-3

This is a domain error in the request that you make

  • Publish your site in the same server domain, for example if the server is
  •   

    link

    Publish your development in

      

    link

    Adding the following to the host file (C: \ WINDOWS \ system32 \ drivers \ etc \ hosts).

    #   127.0.0.1       desarrollo.dominio.com
    

    with this the request is output from the same domain of the server and you delete the CORS

        
    answered by 04.07.2017 в 17:23