0

in reactnavtive app we work with 'http' for url in axios and evry things is ok , now we change 'http' to 'https' but Apis failed ... and app don't work ... why ? please help me.

2 Answers2

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
  • for http is ok , but for https has error Network request failed at XMLHttpRequest.xhr.onerror (VM4 index.bundle:26748) at XMLHttpRequest.dispatchEvent (VM4 index.bundle:32302) at XMLHttpRequest.setReadyState (VM4 index.bundle:31386) at XMLHttpRequest.__didCompleteResponse (VM4 index.bundle:31213) at VM4 index.bundle:31323 at RCTDeviceEventEmitter.emit (VM4 index.bundle:3320) at MessageQueue.__callFunction (VM4 index.bundle:2652) at VM4 index.bundle:2365 at MessageQueue.__guard (VM4 index.bundle:2606) – mahya bakhtiari Jan 11 '21 at 12:15
  • hope you will get the solution from this link https://stackoverflow.com/questions/6825226/trust-anchor-not-found-for-android-ssl-connection – Muhammad Idrees Jan 11 '21 at 13:15
  • finally, I got the solution here https://stackoverflow.com/questions/40240321/how-can-i-implement-ssl-certificate-pinning-while-using-react-native – Muhammad Idrees Jan 11 '21 at 13:42
0

i found answer this question , my url was : 'https://185.305.1.13/index.image.png' , we add domin for images , and url chaghed :'https://image.com/index.image.png'... and revso