3

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)?

Tomas Petovsky
  • 285
  • 4
  • 14
  • "Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port, this may be because it is not running at all or because it is listening on a different port. – HaveNoDisplayName Nov 11 '14 at 13:42
  • You can refer to the following links http://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it and http://stackoverflow.com/questions/24096657/no-connection-could-be-made-because-the-target-machine-actively-refused-it-127-0 – HaveNoDisplayName Nov 11 '14 at 13:43
  • Thank you for your answer. As I wrote in the question, service is running and is reachable via web browser on 127.0.0.1 and also onlocalhost address, but WebClient has problem with localhost address, 127.0.0.1 is fine, so I think, firewall is not an issue here :) – Tomas Petovsky Nov 11 '14 at 14:56
  • 1
    Are you sure that localhost resolves to 127.0.0.1 (and not ::1) on your machine? Can you telnet to localhost port 3000? – Steffen Ullrich Nov 11 '14 at 15:09
  • Steffen, I explored exception message and there was [::1]:30000. So that's the problem. The question is, how can I solve that? – Tomas Petovsky Nov 11 '14 at 15:15
  • 1
    Either listen on ::1 too or define localhost as only 127.0.0.1 in your hosts file so that it does not try to interpret localhost as ::1. – Steffen Ullrich Nov 11 '14 at 15:44
  • Oh God, I'm quite inattentive today. Of course it's IPv6 address and I was not aware of that. Thank you Steffen. So I added `::1 localhost` to the hosts file and change listen address on server to `::1`. Thank you :) – Tomas Petovsky Nov 11 '14 at 16:03

1 Answers1

1

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.

Tomas Petovsky
  • 285
  • 4
  • 14