Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Indy v10 to support IPv4 + IPv6?

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?

like image 470
Casady Avatar asked Mar 01 '13 21:03

Casady


1 Answers

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]/')
like image 107
Remy Lebeau Avatar answered Nov 01 '22 01:11

Remy Lebeau