How to enable ios http requests?

#1

Hi guys, I want to write an app to fetch rss news, that means it must supports both http/https requests. By default, ‘fetch(‘http://website’)’ will be failed and ‘fetch(‘https://website’)’ will be successful.
So, how to enable http requests? I only found ‘infoPlist’ option in documentation that could support my own plist files, but it seems that it can just be used in stand-alone apps, not in debugging mode. What’s the solution? Any help will be good:)

0 Likes

#2

Hi-

We actually disable ATS completely in the Expo client app so you should be able to fetch any URL your phone can connect to, including http ones.

If you are getting an error, its probably because of something else.

Maybe paste more of your code?

0 Likes

#3

Sure.

        dbHandler.transaction(tx => {
            tx.executeSql(someQuery, [], (tx, results) => {
                let sources;
                // some operations here
                sources.forEach((source) => {
                    fetch('**http://some.website**').then(xml => {).catch(e => {console.log('fetch failed', e)});
                });
            });
        });

I did some queries in sqlite, and each query with a fetch, but everytime it went to catch block.
If I changed http to https(that website supports http and https) in the code, everything went Ok.

{
  "expo": {
    "sdkVersion": "19.0.0"
  }
}

This is app.json

{
  "name": "myproj",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-native-scripts": "0.0.40",
    "jest-expo": "~18.0.0",
    "react-test-renderer": "16.0.0-alpha.12"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "node node_modules/jest/bin/jest.js --watch"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "expo": "^19.0.0",
    "react": "16.0.0-alpha.12",
    "react-native": "^0.46.4",
    "react-native-swipeout": "^2.1.3",
    "react-native-xml2js": "^1.0.3",
    "react-navigation": "^1.0.0-beta.11",
    "redux-saga": "^0.15.4"
  }
}

This is package.json

0 Likes

#4

Any suggestions:slight_smile:?

0 Likes

#5

It works.
But wired, I changed no code, a few days later, it went Ok.
So this problem is solved.

0 Likes