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

How to use https agent in React Native? #45373

Closed
Shahanshah-TA opened this issue Jul 11, 2024 · 6 comments
Closed

How to use https agent in React Native? #45373

Shahanshah-TA opened this issue Jul 11, 2024 · 6 comments
Labels
🌐Networking Related to a networking API. Resolution: Answered When the issue is resolved with a simple answer Type: Unsupported Version Issues reported to a version of React Native that is no longer supported

Comments

@Shahanshah-TA
Copy link

Description

I need to call an api with https agent, but React native is not supporting https.

  const cert = await RNFS.readFile(certificatePath, 'utf8');
  const key = await RNFS.readFile(keyPath, 'utf8');
     const httpsAgent = new https.Agent({ //[ReferenceError: Property 'https' doesn't exist]
      cert: cert,
      key: key,
    });
   const response = await axios({
      method: 'PUT',
      url: `URL here`,
      data: data,
      httpsAgent: httpsAgent,
      headers: {
        'Content-Type': 'application/json',
        'Content-Encoding': 'utf-8',
      },
    });

Steps to reproduce

  1. Yarn android

React Native Version

0.71.8

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info

System:
    OS: macOS 14.5
    CPU: (11) arm64 Apple M3 Pro
    Memory: 67.53 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.2 - /opt/homebrew/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - /opt/homebrew/bin/npm
    Watchman: 2024.01.22.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.15.2 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 23.4, iOS 17.4, macOS 14.4, tvOS 17.4, visionOS 1.1, watchOS 10.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 2023.2 AI-232.10227.8.2321.11479570
    Xcode: 15.3/15E204a - /usr/bin/xcodebuild
  Languages:
    Java: 17.0.10 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.8 => 0.71.8 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Stacktrace or Logs

NA

Reproducer

NA

Screenshots and Videos

No response

Copy link

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Jul 11, 2024
Copy link

⚠️ Unsupported Version of React Native
ℹ️ It looks like your issue or the example you provided uses an unsupported version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.

@github-actions github-actions bot added Type: Unsupported Version Issues reported to a version of React Native that is no longer supported 🌐Networking Related to a networking API. and removed Needs: Triage 🔍 labels Jul 11, 2024
@cortinico
Copy link
Contributor

https.Agent is a Node API which is not supported by React Native.

@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Jul 11, 2024
@Shahanshah8791
Copy link

@cortinico any alternative for https.Agent or any suggestion how I can use. I tried multiple node supporting package such as https://www.npmjs.com/package/rn-nodeify https://github.com/parshap/node-libs-react-native but didn't get success.

@Megahedron69
Copy link

@Shahanshah8791 did you find any solution to this?

@Shahanshah-TA
Copy link
Author

No @Megahedron69 I switched to native implementation. If you want you can fork this package rn-nodeify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌐Networking Related to a networking API. Resolution: Answered When the issue is resolved with a simple answer Type: Unsupported Version Issues reported to a version of React Native that is no longer supported
Projects
None yet
Development

No branches or pull requests

4 participants