有关react-native POST请求造成Network request failed解决方法
发布时间:2020-12-15 03:35:37 所属栏目:百科 来源:网络整理
导读: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
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, 即:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |