axios发布请求在React Native ios中工作但不在android中
发布时间:2020-12-15 09:30:51 所属栏目:百科 来源:网络整理
导读:我知道有很多关于这个问题的答案,但我似乎找不到一个对我有用的答案.我正在使用axios向我的服务器发送一个帖子请求,但它在 android中不起作用,尽管它在ios中.我目前正在使用服务器IP地址(不是localhost),我也在请求时发送标题,但它仍然没有通过网络请求andro
我知道有很多关于这个问题的答案,但我似乎找不到一个对我有用的答案.我正在使用axios向我的服务器发送一个帖子请求,但它在
android中不起作用,尽管它在ios中.我目前正在使用服务器IP地址(不是localhost),我也在请求时发送标题,但它仍然没有通过网络请求android.
import axios from 'axios'; const SERVER_URL = 'http://serverip:3000'; export function signin({ username,password }) { return function(dispatch) { axios.post(`${SERVER_URL}/user/authenticate`,{ username,password },{ headers: { 'Content-Type': 'application/json' } }) .then((response) => { console.log('login response',response); dispatch({ type: USER_AUTH,}); AsyncStorage.setItem('token',response.data.token || ''); }) .catch((response) => console.log('user sign in err',response)); }; } 有没有人像我一样有类似的问题,知道如何使这项工作? 谢谢, 解决方法
将标头设置为
headers: { Accept: 'application/json','Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',}, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |