1

I have a strange problem: System.net.HTTPClient seems to ignore hostname settings in C:\Windows\System32\drivers\etc\hosts..

steps to reproduce..

1 Map a hostname on a local ipaddress in C:\Windows\System32\drivers\etc\hosts, eg.:

127.0.0.1 www.google.com

2 flush the dns cache with a console command:

ipconfig /flushdns

3 ping the hostname www.google.com and check if it resolves to 127.0.0.1 (works for me):

ping www.google.com

4 make a request with System.net.HTTPClient (I use Delphi);

aFileStream := TFileStream.Create('C:\response.html', fmCreate);
aHTTPClient := THTTPClient.create;
try
    aHTTPClient.Get('http://www.google.com/', aFileStream);
finally
    aHTTPClient.free;
    aFileStream.free;
end;

HTTPClient returns the real www.google.com page but if I open Internet Explorer and type www.google.com I see my local server.

Why does the HTTPClient not follow the C:\Windows\System32\drivers\etc\hosts setting?

Itchydon
  • 2,293
  • 5
  • 16
  • 30
ar099968
  • 4,434
  • 5
  • 36
  • 88
  • I am working with httpclient as we speak and using HOSTS to test bits & bobs and it behaves exactly as it should (i.e. honouring entries) - are you behind a proxy server of some kind? – Alex K. Jul 14 '17 at 10:13
  • @AlexK. httpclients seems has a own dns cache https://stackoverflow.com/questions/7277582/how-do-i-clear-system-net-client-dns-cache?rq=1 – ar099968 Jul 14 '17 at 10:58

0 Answers0