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?