Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Headers are not being sent in iOS but working in android for Axios React Native

$
0
0

I'm using Axios for sending http requests, it's working fine for Android, but the headers are not sent in iOS, here is my code:

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
        });

and in my interceptor:

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);
});

Any Idea ?


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>