I can access to this link in the web browser. But when it comes to the console or my react code, it keeps failing.
I tried both fetch and axios and none was working. It just keeps giving me ERR_CONNECTION_RESET
and TypeError: Failed to fetch
.
Here is what I've tried:
await fetch('https://api.ipify.org/');
await fetch('https://api.ipify.org?format=json', {
"Access-Control-Allow-Origin": "*"
})
await fetch('https://api.ipify.org?format=json', {
referrerPolicy: 'no-referrer',
})
await fetch('https://api.ipify.org?format=json', { mode: 'no-cors' })
await axios.get('https://api.ipify.org?format=json');
What the right way to get ip?
I just found out that this website needs vpn to be accessed. It is NOT AVAILABLE in my area.
My workaround is letting the backend the fetch the ip from the request. In my case I don't actually need the frontend to get the ip.
I'm keeping this question for people who might run into the same problem as I do instead of deleting it when looking for ipify solutions.