Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 网络请求在react native中设置超时$argument_0失败?_Reactjs_React Native_React Native Android - Fatal编程技术网

Reactjs 网络请求在react native中设置超时$argument_0失败?

Reactjs 网络请求在react native中设置超时$argument_0失败?,reactjs,react-native,react-native-android,Reactjs,React Native,React Native Android,我正在创建一个react本机应用程序来测试我的API,它是托管的。《邮递员》很好用。但是当我使用fetch方法访问我的API时,它给出了“networkrequestfailed”错误。我尝试通过“”此链接获取该方法,该方法工作正常。我如何解决我的问题 您可以使用“”此链接检查我的API。 我还尝试了“”此链接中的步骤。但对我来说什么都不管用。 请帮我解决这个问题 import React,{Component}来自'React'; 进口{ 样式表, 看法 文本, 触控高光, 警觉的 }从“

我正在创建一个react本机应用程序来测试我的API,它是托管的。《邮递员》很好用。但是当我使用fetch方法访问我的API时,它给出了“networkrequestfailed”错误。我尝试通过“”此链接获取该方法,该方法工作正常。我如何解决我的问题

您可以使用“”此链接检查我的API。 我还尝试了“”此链接中的步骤。但对我来说什么都不管用。 请帮我解决这个问题

import React,{Component}来自'React';
进口{
样式表,
看法
文本,
触控高光,
警觉的
}从“反应本机”;
类应用程序扩展组件{
建造师(道具){
超级(道具);
此.state={
uname:'管理员',
upassword:'123',
};    
}
getDataFromAPI=()=>{
//警惕,警惕(“你好”)
const{uname}=this.state;
const{upassword}=this.state;
//控制台警告(uname)
// https://jsonplaceholder.typicode.com/todos/1
取('https://devapps.sansutech.com/EventApp/api/User/GetUser?username=“+联塞特派团{
方法:“获取”
})
.then((response)=>response.json())
.然后((responseJson)=>{
控制台。警告(应答);
})
.catch((错误)=>{
控制台错误(error);
});
};
postDataFromAPI=()=>{
//警惕,警惕(“你好”)
const{uname}=this.state;
const{upassword}=this.state;
//控制台警告(uname)
取('https://devapps.sansutech.com/EventApp/api/User/userLogin', {
方法:“POST”,
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”,
},
正文:JSON.stringify({
用户名:uname,
密码:upassword,
}),
})
.then(response=>response.json())
.然后(responseJson=>{
控制台。警告(应答);
})
.catch(错误=>{
控制台错误(error);
});  
};
putDataFromAPI=()=>{
警惕,警惕(“你好”)
};
deleteDataFromAPI=()=>{
警惕,警惕(“你好”)
};
render(){
报税表(
测试API方法
this.getDataFromAPI()}>
得到
this.postDataFromAPI()}>
邮递
this.putDataFromAPI()}>
放
this.deleteDataFromAPI()}>
删除
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
背景颜色:“#EEEEEE”,
对齐项目:“居中”,
paddingTop:50,
},
标题:{
尺寸:24,
textAlign:'中心',
玛金托普:22,
marginBottom:40,
颜色:“5F6D7A”
},
说明:{
玛金托普:20,
textAlign:'中心',
颜色:“A9A9”,
尺寸:16,
差额:40,
},
按钮容器:{
身高:45,
flexDirection:'行',
为内容辩护:“中心”,
对齐项目:“居中”,
marginBottom:20,
宽度:250,
边界半径:30,
},
登录按钮:{
背景色:“3498db”,
},
按钮文字:{
颜色:“FFFFFF”,
尺寸:20,
}
});
导出默认应用程序;

它发生在POST请求或GET?两种情况下。它对任何方法都不起作用。它给出了相同的错误。它发生在POST请求或GET上?两者都有。它对任何方法都不起作用。它给出了同样的错误。
import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Text,
  TouchableHighlight,
  Alert
} from 'react-native';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      uname: 'admin',
      upassword: '123',
    };    
  }

  getDataFromAPI = () => {
    // Alert.alert("Hi there")
    const {uname} = this.state;
    const {upassword} = this.state;
    // console.warn(uname)
// https://jsonplaceholder.typicode.com/todos/1
    fetch('https://devapps.sansutech.com/EventApp/api/User/GetUser?username='+uname, {
      method: 'GET'
   })
   .then((response) => response.json())
   .then((responseJson) => {
      console.warn(responseJson);
   })
   .catch((error) => {
      console.error(error);
   });
  };
  postDataFromAPI = () => {
    // Alert.alert("Hi there")
    const {uname} = this.state;
    const {upassword} = this.state;
    // console.warn(uname)

      fetch('https://devapps.sansutech.com/EventApp/api/User/userLogin', {
          method: 'POST',
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            user_Name: uname,
            password: upassword,
          }),
        })
          .then(response => response.json())
          .then(responseJson => {
            console.warn(responseJson);
          })
          .catch(error => {
            console.error(error);
          });  
  };
  putDataFromAPI = () => {
    Alert.alert("Hi there")
  };
  deleteDataFromAPI = () => {
    Alert.alert("Hi there")
  };

  render() { 
    return ( 
      <View style={styles.container}>
        <Text style={styles.title}>Test API Methods</Text>
        
        <TouchableHighlight style={[styles.buttonContainer, styles.loginButton]} onPress={() => this.getDataFromAPI()}>
          <Text style={styles.buttonText}>Get</Text>
        </TouchableHighlight>
        <TouchableHighlight style={[styles.buttonContainer, styles.loginButton]} onPress={() => this.postDataFromAPI()}>
          <Text style={styles.buttonText}>Post</Text>
        </TouchableHighlight>
        <TouchableHighlight style={[styles.buttonContainer, styles.loginButton]} onPress={() => this.putDataFromAPI()}>
          <Text style={styles.buttonText}>Put</Text>
        </TouchableHighlight>
        <TouchableHighlight style={[styles.buttonContainer, styles.loginButton]} onPress={() => this.deleteDataFromAPI()}>
          <Text style={styles.buttonText}>Delete</Text>
        </TouchableHighlight>
      </View>
     );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#EEEEEE',
    alignItems: 'center',
    paddingTop:50,
  },
  title:{
    fontSize:24,
    textAlign: 'center',
    marginTop:22,
    marginBottom:40,
    color: "#5F6D7A"
  },
  description: {
    marginTop:20,
    textAlign: 'center',
    color: "#A9A9A9",
    fontSize:16,
    margin:40,
  },
  buttonContainer: {
    height:45,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    marginBottom:20,
    width:250,
    borderRadius:30,
  },
  loginButton: {
    backgroundColor: "#3498db",
  },
  buttonText: {
    color: "#FFFFFF",
    fontSize:20,
  }
});
 
export default App;