1

I created a simple app with react-native, using expo & Axios (for server requests)

Before build, while developing, all https requests worked fine.

After build, when running the apk on a physical device, https is not working at all.

The error I get with Logcat is "Network Error". Other Internet connections (after build) in the app do work, like webview opening a web page or Firebase connections also.

    analyzerApi.post('/analyze', urls) .then((res) => { 
dispatch({type: 'get_result', payload: res.data.analysis})}).catch(err => console.log("Error in getting analyze.. " ,err.name, err.message))

(analyzerApi is an axios instance with baseUrl directed to my server)

Ido Levi
  • 114
  • 6

1 Answers1

0

This call will work for both HTTP and HTTPS Try this example for POST CALL

fetch('http://mywebsite.com/endpoint/', {
      method: "POST",
      headers: {
        // Authorization: "Bearer " + Token,
        Accept: 'application/json',
      'Content-Type': 'application/json'
      },
      body: JSON.stringify({
       // sending data userID username, password, etc
      }),
    })
      .then((response) => response.json())
      .then((responseJson) => {
       // Response will here
      })
      .catch((error) => {
        alert(error);
      });

Try this example for GET CALL

fetch('http://mywebsite.com/endpoint/', {
      method: "GET",
      headers: {
       // Authorization: "Bearer " + Token,
       // OR USER name PASSworrd
       Accept: 'application/json',
      'Content-Type': 'application/json'
      },
    })
      .then((response) => response.json())
      .then((responseJson) => {

        // Response will here
      })
      .catch((error) => {
        alert(error);
      });
Muhammad Idrees
  • 570
  • 4
  • 10