android物理设备上的网络请求失败

时间:2019-09-17 05:15:57

标签: reactjs react-native

当我使用fetch()进行http调用时,它使我“网络请求失败”。这是在Android物理设备上发生的。 (因为我正在使用expo,所以无法在android或iOS目录中进行任何修改)

passcodes = async () => { 
    let data = {
      method: 'POST',
      credentials: 'same-origin',
      cache: 'no-cache',
      mode: 'same-origin',
      body: JSON.stringify({
          "mobileNumber": this.state.mobileNumber,
          "customerId": "my_customer_id",
          "sessionId": "my_session_id"
      }),
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json'
      }
    }
    return await fetch(BaseUrl + 'my_endpoint_url', data)
       .then((response) => response.json())
       .then((responseJson) => {
         this.setState({
            passCodeText: passCodeData[0],
            passCode: passCodeData[1],
            visibleModal: 1,
            backgroundImage: responseJson.generatePasscodeImage
         });
        })
       .catch((error) => {
         console.error(error);
       });
  };

0 个答案:

没有答案