标头未在iOS中发送,但在Axios React Native的android中工作

时间:2019-10-30 13:55:34

标签: ios react-native axios

我正在使用Axios发送http请求,它在Android上运行正常,但是标头未在iOS中发送,这是我的代码:

Axios.get('/patient/doctor/search?page_size=10&page=1')
        .then(function (response) {
          // handle response
        })
        .catch(function (error) {
            // here it goes with 401 error code
        });

并在我的拦截器中

Axios.interceptors.request.use(async config => {
try {
    const user = await AsyncStorage.getItem('user');
    const userData = JSON.parse(user);
    if (userData.token) {
        config.headers = {
            ContentType: 'application/json',
            Authorization: 'Bearer [JWT-TOKEN]'
        }
    } else {
        config.headers = {
            ContentType: 'application/json'
        };
    }
} catch (e) {
    config.headers = { 'ContentType': 'application/json; charset=utf' };
}
return config;
}, error => {
    return Promise.reject(error);
});

有什么想法吗?

0 个答案:

没有答案