axios post请求在React Native ios中工作但在android

时间:2017-07-18 18:23:32

标签: android react-native react-native-android axios

我知道有很多关于这个问题的答案,但我似乎无法找到适合我的问题。我使用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));
  };
}

enter image description here 有没有人像我一样有类似的问题,知道如何使这项工作?

谢谢,

1 个答案:

答案 0 :(得分:0)

将标题设置为

  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  },
相关问题