IdHTTP1 - Error Connecting With SSL

Hi,

I'm trying to connect to google translate's API.  I'm running Delphi7 
and Indy 9.00.10.  When trying to connect with the code below I am
getting "Error connecting with SSL."  I have downloaded the
"libeay32.dll" and "ssleay32.dll" from indy.fulgan.com/SSL/Archive/.  I
have been researching this for some time and trying different settings
but no luck.  BTW, the code below connects fine using DelphiXE and the
version of Indy that comes with XE.  Unforunately I need it to work
with Delphi 7.  With the new google translate API you need a billable
account set up with I have.

Any ideas would be appreciated.

Thanks,

Dexter

Code

function TForm1.translate(ss,lng:string):string;
var s:widestring;
a,b:integer;
http:tidhttp;
sKey : String;
FSSL : TIdSSLIOHandlerSocket;
begin
  sKey := 'yourgooglekeygoeshere';
  http:=tidhttp.Create(nil);

  FSSL := TIdSSLIOHandlerSocket.Create(nil);
  HTTP.IOHandler := FSSL;

  s:=http.Get('https://www.googleapis.com/language/translate/v2?key='+sKey
  +'&source=en&target=de&q=Hello%20world');
  a:=posex('›',s,pos('‹textarea',s));
  b:=posex('‹/textarea›',s,a);
  result:=copy(s,a+1,b-a-1);
  http.Free;
end;

--
0
Dexter
9/15/2012 4:04:47 PM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

3 Replies
11603 Views

Similar Articles

[PageSpeed] 22

Dexter McKenzie wrote:

 > I'm trying to connect to google translate's API.  I'm running Delphi7
 > and Indy 9.00.10.
....
 > but no luck.  BTW, the code below connects fine using DelphiXE and the
 > version of Indy that comes with XE.  Unforunately I need it to work
 > with Delphi 7.

The current Indy version (10.5.9) can be used with Delphi 7, either 
installed as packages or by adding the Indy source directories 
(Lib/Core, Lib/Protocols and Lib/System) to the project search paths.

Hope this helps
-- 
Michael Justin
0
Michael
9/15/2012 6:38:08 PM
Dexter wrote:

> I'm running Delphi7 and Indy 9.00.10.

The last version of Indy 9 was 9.0.50.

> When trying to connect with the code below I am getting "Error connecting 
with SSL."

You are not configuring any of the properties for TIdSSLIOHandlerSocket, 
so the defaults are likely not suitable for Google's requirements.  For example, 
the default value of the SSLOptions.Method property in Indy 9 is sslvSSLv2, 
but is sslvTLSv1 in Indy 10.  It is very rare that anybody uses SSL v2 nowadays.

Try this:

{code:delphi}
function TForm1.translate(ss,lng:string):string;
var
  s: String;
  a, b: Integer;
  http: TIdHTTP;
  sKey : String;
  FSSL : TIdSSLIOHandlerSocket;
begin
  sKey := 'yourgooglekeygoeshere';
  http := TIdHTTP.Create(nil);
  try
    FSSL := TIdSSLIOHandlerSocket.Create(http);
    FSSL.SSLOptions.Method := sslvTLSv1; // or sslvSSLv23, which is used 
as a wildcard for dynamic version negotiating...
    http.IOHandler := FSSL;

    s := http.Get('https://www.googleapis.com/language/translate/v2?key='+sKey+'&source=en&target=de&q=Hello%20world');
    a := PosEx('>', s, Pos('<textarea', s));
    b := PosEx('</textarea>', s, a);
    Result := Copy(s, a+1, b-a-1);
  finally
    http.Free;
  end;
end;
{code}

--
Remy Lebeau (TeamB)
1
Remy
9/17/2012 5:56:03 PM
Hi  Remy,

That works!  Thank you very much!

Dexter
0
Dexter
9/20/2012 7:56:21 AM
Reply: