Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1495

React Native API calls failing under company proxy or VPN with axios or fetch ( only HTTPS )

$
0
0

I just created a React Native app and I want to test API calls. Since I'm working in a company, my computer is under a proxy or VPN when I'm working remotely.

The problem is that I have a GET API with HTTPS for testing. It works fine on Postman and in the browser (it returns a response), but in my app using axios or fetch, it doesn't work:

 const getAPIping = async () => {      try {      const response = await axios.get('https://xxxx.com/api/config/ping',        {          headers: {            Accept: 'application/json','Content-Type': 'application/json',          },        },      );      setDataApi(response.data);      console.log('data:', response.data);    } catch (error) {      console.log("Erreur :", error);    }  };

I tried configuring the proxy with axios but without success:

  const response = await axios.get('https://xxxx.com/api/config/ping',        {          headers: {            Accept: 'application/json','Content-Type': 'application/json',          },        },        {          proxy: {            host: 'proxy.companyname.com',            port: 8080,            auth: {              username: 'mysessionlogin',              password: 'mysessionpassword',            },          },        },      );

It's important to note that this API is only accessible internally (through proxy or VPN).

Another internal API with HTTP works perfectly fine, but the same web service with HTTPS doesn't work. So I tried installing the SSL certificates from the web service via the browser and added them to the emulator in the CA certificate section (I'm not sure if this is the correct approach), but it still doesn't work.

the error i got is:fetch > Network request failedaxios > AxiosError: Network Error

EDITI also tried a public request (in HTTPS): https://jsonplaceholder.typicode.com/todos/1. It always works in a browser and with axios/fetch when I'm not on a proxy/VPN, but it doesn't work in my app when I'm on a VPN/proxy, It doesn't return any response/error


Viewing all articles
Browse latest Browse all 1495

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>