3

The following is the code that i have used to make a fetch request. I seem to be facing an issue only with https request and not http in android. I am using Android studio with an emulator to develop the code.

fetch('https://facebook.github.io/react-native/movies.json')
      .then((response) => response.json())
      .then((responseJson) => {
        console.log("Success");
      })
      .catch((error) => {
              console.error(error);
      });   

The response I get is as follows;

 D:\RNApp\newtest\TheTestApp\node_modules\react-native\Libraries\Core\ExceptionsManager.js:73 TypeError: Network request failed
        at XMLHttpRequest.xhr.onerror (D:\RNApp\newtest\TheTestApp\node_modules\whatwg-fetch\fetch.js:441)
        at XMLHttpRequest.dispatchEvent (D:\RNApp\newtest\TheTestApp\node_modules\event-target-shim\lib\event-target.js:172)
        at XMLHttpRequest.setReadyState (D:\RNApp\newtest\TheTestApp\node_modules\react-

native\Libraries\Network\XMLHttpRequest.js:569)
    at XMLHttpRequest.__didCompleteResponse (D:\RNApp\newtest\TheTestApp\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:399)
    at D:\RNApp\newtest\TheTestApp\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:505
    at RCTDeviceEventEmitter.emit (D:\RNApp\newtest\TheTestApp\node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:181)
    at MessageQueue.__callFunction (D:\RNApp\newtest\TheTestApp\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:353)
    at D:\RNApp\newtest\TheTestApp\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:118
    at MessageQueue.__guardSafe (D:\RNApp\newtest\TheTestApp\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:316)
    at MessageQueue.callFunctionReturnFlushedQueue (D:\RNApp\newtest\TheTestApp\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:117)

I am currently using react-native v0.53.3 . I have been searching for a solution to this problem for quite some time. If someone can please help me it would be great.

Thanks.

3
  • Is the time in the emulator set correctly? This is important to verify the certificate. Commented Mar 7, 2018 at 15:29
  • Yes, the time is set to my system time. Commented Mar 7, 2018 at 15:31
  • I was concerned if it was a network issue with company that i work for, but i guess its safe to say its not because http seems to work ok. Also, when i try and implement a email and password login using google's firebase i seem to be facing a "auth/network-request-failed" issue which i am pretty much guessing is the same as the issue shown above. Commented Mar 7, 2018 at 15:34

1 Answer 1

2

After much research and brain wrecking, i found out that the problem was pretty simple. The network that I use has a proxy server that encrypts all SSL traffic. So the solution was to install the associated certificates into the emulator.

So from my desktop browser which is connected to the same network, i downloaded all the certificates associated with that proxy server and imported it into the SD card (storage) of my emulator. This import and installation can be done by following the steps mentioned in this post.

Once this was done, i re-ran the above code and i found that the response was coming through successfully. Hope this will help anyone who is stuck in the same situation as mine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.