Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-native fetch() method not working for HTTPS requests but is working with HTTP requests [Android] #25471

Closed
ramonvermeulen opened this issue Jul 3, 2019 · 3 comments
Labels
Bug 🌐Networking Related to a networking API. Platform: Android Android applications. Platform: Linux Building on Linux. Resolution: Locked This issue was locked by the bot.

Comments

@ramonvermeulen
Copy link

ramonvermeulen commented Jul 3, 2019

When using the fetch() method with HTTPS I am getting a TypeError: Network request failed. I've tested this with different HTTP and HTTPS API's. I did test this on android only because I don't have an iOS device at the moment.

Example code:

  try {
    const res2 = await fetch(`http://www.mocky.io/v2/5d1c6ba4340000ad67b5fd58`);
    console.log(await res2.json()); // logs a fine response
  } catch (error) {
    console.log(error);
  }
  try {
    const res2 = await fetch(`https://www.mocky.io/v2/5d1c6ba4340000ad67b5fd58`);
    console.log(await res2.json());
  } catch (error) {
    console.log(error); // logs the error
  }

The error message:

TypeError: Network request failed
    at XMLHttpRequest.xhr.onerror (whatwg-fetch.js:504)
    at XMLHttpRequest.dispatchEvent (event-target.js:172)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
    at XMLHttpRequest.js:507
    at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
    at MessageQueue.__callFunction (MessageQueue.js:366)
    at MessageQueue.js:106
    at MessageQueue.__guard (MessageQueue.js:314)
    at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)

React Native version:

$ react-native info
info 
  React Native Environment Info:
    System:
      OS: Linux 4.18 Ubuntu 18.10 (Cosmic Cuttlefish)
      CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
      Memory: 919.79 MB / 15.40 GB
      Shell: 4.4.19 - /bin/bash
    Binaries:
      Node: 11.10.1 - /usr/local/bin/node
      npm: 6.7.0 - /usr/local/bin/npm
    SDKs:
      Android SDK:
        API Levels: 23, 26, 27, 28
        Build Tools: 27.0.3, 28.0.3, 29.0.0
        System Images: android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
    npmPackages:
      react: ~16.8.6 => 16.8.6 
      react-native: ~0.59.10 => 0.59.10 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native: 0.59.10
  1. Create a react-native application running on react-native 0.59.10
  2. Create a mock api which allows HTTP and HTTPS, for example at www.mocky.io or use an own API which accepts both protocols.
  3. Make an API request using the fetch() method using both HTTP and HTTPS.

Describe what you expected to happen:
To get a valid response from my HTTPS call without TypeError: Network request failed

@ramonvermeulen ramonvermeulen changed the title react-native fetch() method not working with HTTPS but is working with HTTP react-native fetch() method not working with HTTPS but is working with HTTP [Android] Jul 3, 2019
@react-native-bot react-native-bot added Platform: Android Android applications. 🌐Networking Related to a networking API. Platform: Linux Building on Linux. labels Jul 3, 2019
@ramonvermeulen ramonvermeulen changed the title react-native fetch() method not working with HTTPS but is working with HTTP [Android] react-native fetch() method not working for HTTPS requests but is working with HTTP requests [Android] Jul 3, 2019
@ramonvermeulen
Copy link
Author

Issue can be closed.
Problem solved, SSL chain certificate was not valid.
Check your certificate through https://www.sslshopper.com/
A valid certificate should have everything passed and on green, you can't see this with your normal web browser.

Good certificate example output:

image

Wrong certificate example output:

image

@manojalwisnz
Copy link

@ramonvermeulen , this is really helpful and saved my time.

@sudo-von
Copy link

@ramonvermeulen thank you so much, it solved my problem :) i had the same error, for those that use apache this problem is generated when you don't specify this line on the default-ssl.conf
SSLCertificateChainFile your_route/bundle.crt

@facebook facebook locked as resolved and limited conversation to collaborators Jul 3, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug 🌐Networking Related to a networking API. Platform: Android Android applications. Platform: Linux Building on Linux. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants