iosreact-nativehttpcross-platformgeneral-network-error

API not working on react-native without SSL


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?


Solution

  • For testing, you can disable ATS entirely using

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