skip to Main Content

I have been looking for the solution of a similar question but I couldn’t find any. So that’s why I am asking it here.

So I have deployed my api's on an AWS instance and whenever I try to access the api’s from the browser they work properly. i.e if I do http://25.234.23.53:3030 I get the success message, but for some reason I am not able to use the AWS instance IP and port to call the API’s from my react native Ios simulator.

Whenever I am calling the API from my react-native app, I’m getting this:

Network Error

and referring to another similar question asked on stack overflow, I have also tried using this approach in my app’s info.plist:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

"react-native version": "0.68.2",

Please guide me how can I allow my app to use http calls from my AWS instance?

2

Answers


  1. Chosen as BEST ANSWER

    Apparently, I had the fix within my code as mentioned by @Paulw11 within the reply as well.

    I just trimmed the following code:

    <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSExceptionDomains</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
    

    into this:

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

  2. For testing, you can disable ATS entirely using

    <key>NSAppTransportSecurity</key>
    <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
    </dict>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search