question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to request anonymously via Axios?

See original GitHub issue

I want to send a GET request to a url via axios.

It seems the website can recognize me via cookies and is redirecting the url to a page where logged in users are moved to.

I want to send a request as if I were doing it from an incognito tab

I have tried using withCredentials: false config.

This does not seem to have any effect with true or false in my case.

 axios({
        url : url,
        method: 'get',
        maxRedirects: 15,
        headers: {
          'Content-Type': 'text/html',
          'Access-Control-Allow-Origin': '*',
          'Access-Control-Allow-Methods':'GET',
        },
        withCredentials: false, // without cookies so no login
      })
      .then((res) => {
         console.log("Response", res.data)
      })
      .catch((err) => {
         console.log("Error with fetch: ", err)
      })
    });

  • Axios version: 0.19.0
  • Environment: Browser

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:18

github_iconTop GitHub Comments

8reactions
mamsoudicommented, Oct 30, 2021

Any updates on the issue, we’re in the same situation, and fetch works perfectly with credentials: 'omit'. Our situation is that we have two applications under the same origin; One uses JWT and the other authenticates using Cookies, and we don’t want to include Cookies in the one with JWT but it just simply doesn’t work.

This gets more problematic since Axios automatically includes Cookies, if we wanted to use Axios for things like Upload requests and showing progress which currently fetch doesn’t support, we’re completely out of options. This basically renders the entire token authentication obsolete in our other app.

I understand that this is a limitation of XHR but does this mean that I’m completely stuck with fetch?

7reactions
Doogiemuccommented, Jan 21, 2020

Had the same problem and found out something new: Axios seems to always add the “Cookie” header when the request goes to the same origin. But it does not automatically add the “Cookie” header when you do a valid CORS request.

Which is strange. And yes the withCredentials configuration variable doesn’t seem to have any effect on this at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to request anonymously via Axios? - Stack Overflow
I have tried using withCredentials: false config. This does not seem to have any effect with true or false in my case. axios({...
Read more >
Contact Us - Axios
If you're having trouble subscribing to or unsubscribing from Axios newsletters, or running into issues with our website, please reach out to our...
Read more >
All You Need to Know About Axios - Pluralsight
This guide takes a deep dive into some cool features of Axios like making concurrent requests, consuming arrays, and more.
Read more >
How to handle errors with Axios request - Educative.io
Line 8: Use the get method of the axios object to make a get request. The URL provided to the get method points...
Read more >
Axios vs. Fetch API – Which is Better For HTTP Requests?
The response data is available as a JSON by default, hence we can immediately access it using the data property. It uses XMLHttpRequest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found