0

I'm developing a React Native app that makes a POST request to the following endpoint:

https://www.animeunity.so/livesearch

When I test the request extracted from my browser in Insomnia, it works perfectly. However, when I run the same request inside my app using Axios, I get a 419 status code ("Page Expired" or CSRF error).

Below is the exact code generated by Insomnia (with current tokens and cookies replaced by placeholder values):

async function search() {
  var axios = require("axios").default;
  var options = {
    method: "POST",
    url: "https://www.animeunity.so/livesearch",
    headers: {
      // Consolidated cookie header as sent by Insomnia:
      Cookie: "XSRF-TOKEN=YOUR_XSRF_TOKEN; animeunity_session=YOUR_SESSION_COOKIE",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0",
      Accept: "application/json, text/plain, */*",
      "Accept-Language": "en-US,en;q=0.5",
      "Accept-Encoding": "gzip, deflate, br, zstd",
      "X-Requested-With": "XMLHttpRequest",
      "X-CSRF-TOKEN": "YOUR_X_CSRF_TOKEN",
      "Content-Type": "application/json;charset=utf-8",
      "X-XSRF-TOKEN": "YOUR_X_XSRF_TOKEN",
      Origin: "https://www.animeunity.so",
      DNT: "1",
      "Sec-GPC": "1",
      "Alt-Used": "www.animeunity.so",
      Connection: "keep-alive",
      Referer: "https://www.animeunity.so/"
    },
    data: { title: "Fullmetal Alchemist Brotherhood" },
  };

  axios
    .request(options)
    .then((response) => {
      console.log("Response:", response.data);
    })
    .catch((error) => {
      console.error(
        "Error:",
        error.response ? error.response.data : error.message
      );
    });
}

The code was tested in the Expo Go app.

Error 419 should usually be returned for missing csrf token, but I'm passing it in the headers.

I’ve tried modifying the request (and rewriting using the fetch API) without success. What differences between Insomnia and a React Native environment (such as cookie handling, header modifications, or network stack differences) could cause the server to reject my request with a 419 error?

Are there any known issues or additional configuration steps (for example, using a cookie jar library or setting additional headers) required in React Native to ensure proper CSRF token and cookie handling with Axios?

Any insights or suggestions to help resolve this discrepancy would be greatly appreciated!

1
  • 1
    you can try adding axios.defaults.withCredentials = true. Otherwise you need to check the api befor diving into axios problems. Check the Origin and Referer match in the header, verify you can make a request using curor postman (that its not an issue with the api) Commented Feb 10 at 19:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.