有关react-native POST请求造成Network request failed解决方法

前端之家收集整理的这篇文章主要介绍了有关react-native POST请求造成Network request failed解决方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Android端,我们在POST请求时

componentWillMount(){@H_403_3@

var body = {"id": 1};

fetch("http://xxx",{

method: "POST",@H_403_3@ body: JSON.stringify(body),@H_403_3@ }) @H_403_3@ .then((response) => response.json()) @H_403_3@ .then((responseData) => { @H_403_3@ ToastAndroid.show(""+responseData.data,ToastAndroid.SHORT); @H_403_3@ }) @H_403_3@ .catch((error) => { @H_403_3@ ToastAndroid.show("err :"+error ,ToastAndroid.SHORT); @H_403_3@

}).done();

}

总会报错Network request Failed

其实这是针对Android的HTTP请求的协议

解决方法是:Post数据要带headers,里面要有Content-Type,

即:

猜你在找的React相关文章