'Fetch not sending Authorization header in ios

I use two fetch functions, one to log in another get data from my API.

login works fine but the second fetch throws an error in ios. it works fine on android

Authorization header is not being sent from ios

this is my code:

import { Alert } from 'react-native';
import { rootUrl } from './index';
import { translate } from '../../config/translation';
import store from './../store';
import NavigatorService from '../../config/navigator';

export default function fetchTree(Authorization) {
  fetch(`${rootUrl}/tree`, {
    method: 'GET',
    headers: {
      Authorization,
      'Content-Type': 'application/json',
    },
  })
    .then((response) => {
      console.log(response);
      store.dispatch({ type: 'loading', payload: false });
      if (response.status !== 200) {
        Alert.alert(
          translate('Access Denied'),
          translate('You are not Authorized to view this content'),
          [{ text: translate('OK') }],
          {
            cancelable: false,
          },
        );
        return 0;
      }
      return response.json();
    })
    .then((responseJson) => {
      if (responseJson !== 0) {
        const tree = responseJson[0].tree;
        NavigatorService.reset('Home', { tree });
      }
    });
}

this is the response I get from the server:

enter image description here

Solution:

The URL needs a trailing /

So it should have been ${rootUrl}/tree/ instead of ${rootUrl}/tree



Solution 1:[1]

based on react native

documentation fetch will work for IOS & Android so i don't think the error on fetch i think there is another error did you add network permission in your info.plist

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ahmed farag mostafa