【发布时间】:2017-12-23 18:30:12
【问题描述】:
我知道关于这个问题有很多答案,但我似乎找不到适合我的答案。我正在使用 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));
};
}
谢谢,
【问题讨论】:
-
你确定它适用于 ios 但不适用于 android 吗?还是相反
-
我确定它只适用于 ios,不适用于 android
-
奇怪,我以为ios只允许连接到https
-
哦,对不起,我在 ios 端使用“https”,但我的问题是相同的代码库在 android 中不起作用。我尝试使用不同的组合(http、https)运行,但它们都不起作用,这就是我发布这个问题的原因。
-
@ckim16 你在这里找到问题了吗?
标签: android react-native react-native-android axios