Question

I'm having a persistent problem using Indy 10 where I am posting a string of XML encoded as a TIdMultiPartFormDataStream, the code that I am using to invoke the POST is given below. A majority of the time, this works no problem, however I am getting a repeated error when running on Windows 7 that throws a #10060 Connection Timeout socket error only when the XML string is longer than 32767 bytes, anything under that size works without a problem.

I have verified that it is not related to the server I am posting to, as there is no problem for messages of any size sent with the same code/application on Windows XP.

IdHTTP2 := TIdHTTP.Create();

UsingHTTPS := (Pos(LowerCase('https://'), Trim(LowerCase(URL)))> 0);
if UsingHTTPS then begin
IdSSLIOHandlerSocketOpenSSL2:=TIdSSLIOHandlerSocketOpenSSL.Create();
  with IdSSLIOHandlerSocketOpenSSL2 do
  begin
    SSLOptions.Method := sslvTLSv1;
    SSLOptions.Mode := sslmUnassigned;
    SSLOptions.VerifyMode := [];
    SSLOptions.VerifyDepth := 0;
    Port := 443;
  end;
 end; //if UsingHTTPS


try
  try
    with IdHTTP2 do
    begin //with some browser style defaults
      AllowCookies := False;
      ProxyParams.BasicAuthentication := False;
      //ProxyParams.ProxyPort := 0;
      Request.ContentLength := data.Size;
      Request.host := '';
      Request.CustomHeaders.Clear;
      Request.Accept := '';
      Request.ContentEncoding := '';
      IOHandler:=IdSSLIOHandlerSocketOpenSSL2;
      ReadTimeout := -1;
    end;


     //http post
    IdHTTP2.Post(URL, data, response);

Does anyone have any recommendations to solve this problem? I tried to set the ReadTimeout variable but this had no change. Any pointers to solve this problem would be much appreciated.

Was it helpful?

Solution

TIdSSLIOHandlerSocketOpenSSL sets a hard-coded 30 second read/write timeout on an SSL socket on Windows Vista+ when the ReadTimeout property is <= 0, so chances are the connection is slow enough to take longer than 30 seconds to transmit data. Try setting the ReadTimeout property to a higher value to see if it delays the error. If so, then there really is a transmission issue.

You can use a packet sniffer, such as Wireshark, to make sure data is actually being transmitted back and forth in a timely manner. Also look at the call stack when the exception is raised to see if the timeout is occurring during the SSL handshake, while sending the HTTP request, or while receiving the HTTP response. That will help determine whether it is an issue with OpenSSL, Indy, or the server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top