Search code examples
iosreact-native

react-native POST request works on Android but not IOS


The API_URL is https. It works on Android.

On iPhone the request doesn't even make it to the server. Why isn't it working on iPhone?

Here is my request:

export async function createGroup(
  getToken: GetToken,
  group_name: string,
  is_public = false,
): Promise<Group | string> {
  return fetch(`${API_URL}/api/groups/`, {
    headers: {
      Authorization: `Bearer ${await getToken()}`,
      "Content-Type": "application/json",
      Accept: 'application/json',
    },
    method: "POST",
    body: JSON.stringify({
      group_name,
      is_public,
    }),
  })
    .then((response) => {
      return response.json();
    })
    .then((json) => {
      return json.group;
    }).catch((error) => {
      return JSON.stringify(error);
    });
}


Solution

  • So the issue was the trailing slash; apparently iOS/android handle it differently! And on iOS having it there completely broke the request.

    Removing the trailing slash fixed the issue.