gkeenley
gkeenley

Reputation: 7348

React Native for iOS: "network request failed" for one URL but not others

In my React Native app, I'm trying to make an API call with this code:

test = async () => {
    try {
      let a = await fetch('https://rxapitest.alliancepharmacygroup.ca:12345/', {
        method: 'GET',
      }).then(response => {
        console.log("success")
      })
    } catch(err) {
      console.log("error")
    }
  }

On Android this works fine. In Postman the request works fine. And when I replace the URL with https://google.com or something, it works fine. So it seems that the problem is with this particular URL for iOS only.

Here's my stacktrace:

enter image description here

Does anyone know how I can approach this?

Upvotes: 1

Views: 1235

Answers (1)

CR7
CR7

Reputation: 587

Did you try to add the NSAppTransportSecurity policy in info.plist? Like that:

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

Upvotes: 2

Related Questions