Question

With the following code I can get the content of an IPv4 website:

uses 
  IdHttp;

IdHttp1 := TIdHttp.Create(nil);
try
  Result := IdHttp1.Get('http://www.heise.de/')
finally
  IdHttp1.Free;
end;

but when I try to connect to an IPv6 website I get Socket Error # 11004:

IdHttp1 := TIdHttp.Create(nil);
try
  Result := IdHttp1.Get('http://www.six.heise.de/')
finally
  IdHttp1.Free;
end;

I can ping www.six.heise.de just fine (IP 2a02:2e0:3fe:100::6:) and Firefox displays the website without problems.

What I need to change in Indy (latest V10 build from SVN) to connect to both IPv4 and IPv6 websites?

Was it helpful?

Solution

TIdTCPClient needs to be told whether to use IPv4 or IPv6 for its socket and hostname-to-IP resolutions. That is done using the TIdTCPClient.IPVersion property. However, TIdHTTP is a special case because it manages the TIdTCPClient properties and connection internally, including the IPVersion. TIdHTTP sets the IPVersion based on the URL being requested. In order to request a URL containing an IPv6 hostname, it needs to be wrapped in brackets, eg:

Result := IdHttp1.Get('http://[www.six.heise.de]/')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top