I am attempting to access API data using Axios, but I am facing an issue where Axios is unable to retrieve the data. Interestingly, when I tested the same API endpoint with Postman, I was able to successfully access the data. Upon further investigation, I noticed that Postman stores a login cookie which helps in accessing the data. I tried replicating this behavior with Axios but unfortunately, it did not work.
I read that
axios.defaults.withCredentials = true
should be used, but even after implementing this, I am still facing difficulties. It's possible that I might be making an error in my implementation.
Below is the code snippet I have been working on:
getData() {
axios.defaults.withCredentials = true;
let url = "***"
axios
.get(url)
.then(response => {
this.name = response
}).catch((error) => {
this.name = error;
})
}
I appreciate any help or insights you can provide! Thank you!