WebClient can't download string from localhost

2.9k Views Asked by At

I'd like to download content from https://localhost:3000/ using WebClient.DownloadString method, but this call ends up with SocketException: No connection could be made because the target machine actively refused it although the address is reachable via browser.

I figured out, that request is successful when I replace with 127.0.0.1 (so the address is https://127.0.0.1:3000).

How can I fix it so that I can use localhost address (it needs to be localhost due to SSL certificate)?

1

There are 1 best solutions below

0
On BEST ANSWER

WebClient was translating localhost address to IPv6 address ::1 and I was not aware of that. So I added new line to hosts file ::1 localhost and change server listen address to the ::1.