How to allow cross-origin requisitions?

3

I have an Swift App that consumes data from an API, in swift I had to enable it in info.plist adding:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

I need to enable the same angular, how is it? I saw in some places saying that I need to do something on the server but I did not even need to ...

Message:

  

Cross-origin request blocked: Same source policy (Same   Origin Policy) prevents the remote resource from being read    link . (Reason: CORS header   'Access-Control-Allow-Origin' is not present).

    
asked by anonymous 18.04.2016 / 19:35

2 answers

1

To disable same origin policy try starting Chrome with the following flags:

--disable-web-security --user-data-dir

Font

    
04.05.2016 / 21:09
0

Hello, what programming language are you using on your server (web services / API)?

I'll leave an example below in php and can be done easily in other languages.

To enable CORS you simply return a header on the requested page the header is Access-Control-Allow-Origin and its value is *

  

Example in PHP

<?php
        //habilitando o cors
        header("Access-Control-Allow-Origin: *");
    
02.04.2017 / 01:18