Wednesday, September 10, 2025
HomeiOS DevelopmentAndroid app returning 401 error on API name with token, works tremendous...

Android app returning 401 error on API name with token, works tremendous on iOS


I’m engaged on a cell software the place login works completely on each iOS and Android. Nevertheless, after logging in, when I attempt to make subsequent API requests with the authorization token on Android, I persistently get a 401 Unauthorized error. The identical API calls work tremendous on iOS.

export const poster = async ({url, technique = 'POST', physique}: PosterType) => {
  const {cookie} = retailer.getState().userReducer;
  // Solely add Authorization header if cookie exists

  return await axios({
    url,
    technique: technique,
    headers: {
      Authorization: `Bearer ${cookie}`,
      'Content material-Kind': 'software/json',
      Settle for: 'software/json',
    },
    knowledge: physique,
    withCredentials: false,

    // mode: 'cors',
  })
    .then(async worth => {
      const knowledge = await worth.knowledge;

      if (!worth.standing) {
        throw new Error(knowledge.message ?? knowledge?.error?.message);
      }
      return knowledge;
    })
    .catch(error => {
      // console.log(JSON.stringify(error), 'errorerrorerrorerror');
      throw error;
    });
};

Why is that this situation taking place on Android solely? What may trigger the headers or token to not be despatched or parsed correctly on Android?
How can I repair this situation on Android to make sure that the authorization token is handed accurately and authenticated by the server, because it does on iOS?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments