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

来源:互联网 发布:手机 usb 共享网络 编辑:程序博客网 时间:2024/06/04 18:55

Android端,我们在POST请求时

componentWillMount(){

      var body = {"id": 1};

       fetch("http://xxx", {

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

        }).done();

}

总会报错Network request failed。

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

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

即:


0 0
原创粉丝点击