react-native检索响应获取不适用于我的android手机

时间:2020-04-27 07:50:03

标签: json react-native fetch

当我在android studio中的虚拟设备上对其进行测试时,代码正常。但是,当我在手机上对其进行测试时,来自提取的响应并不正确。 为什么呢 fetch的响应为json:{“ sCode”:“ 0”,“ bErreur”:false,“ sMessage”:“ 157#Denis”}

感谢您的帮助。

代码:

_handleResponse(reponse){

      alert(reponse.sCode);
      this.setState({messageString:'ok'});
      //this.props.navigation.navigate('Map');
    }

    onLogin () { 
      var email = this.state.Identifiant;
      const url ='https://www.wapps-saas.com/login2';//+email+'/azerty13/49';  
        console.log(this.state.Identifiant);
        //this.setState({messageString:url});
        this.setState({messageString:''});
        if (this.state.Identifiant!='')
        {
          var data = {
            email: this.state.Identifiant,
            mot_de_passe: this.state.Password,
            nIDAppli:this.state.IdAppli

           };
           try {

            let response = fetch(
             url,
             {
               method: "POST",
               headers: {
                "Accept": "application/json",
                "Content-Type": "application/json",
                "Host":"www.wapps-saas.com"
               },
              body: JSON.stringify(data)
            }
           ) .then(response => response.json()).then((json)=>{this._handleResponse(json)}).finally(()=>{this.setState({messageString:'End'})}); //)/this._handleResponse(json)

          } catch (errors) {

            console.log(errors);

            this.setState({messageString:errors});

           } 
        }

        else{
            this.setState({messageString:'identifiant obligatoire'});

        }
    }

0 个答案:

没有答案