IdHTTP in a loop

Giganews Newsgroups
Subject: IdHTTP in a loop
Posted by:  Michael Fritz (spam_athome@yahoo.de)
Date: Mon, 28 Jul 2003

HI,

I'm using the following code fragment to validate some URLs: The URLs are
stored in memToCheck. I've also added an event for OnStatus to get some
feedback from IdHTTP.

Every time when IdHTTP1.Head is called I first get "Connection disconnected"
and immediately afterwards "Connection is established" (German translation-
English may be slightly different). This repeats each time IdHTTP1.Head is
called.

I wanted to save some time and not reconnect more than once to the proxy but
it seems that this is an built in feature? I think if I do the URL checking
in a multithreaded (so far nothing is implemented) application, I have to
use multiple instances of IdHTTP anyway - is this assumption correct?

BTW. If I put IdAntiFreeze to my very simple (test-)application I always get
a -1 IdHTTP1.ResponseCode back no matter which value I set for ReadTimeout.
How could I avoid this?

cu,
Michael

-------------------code snippet---------------------------
procedure TForm1.Button1Click(Sender: TObject);
  var
      oRequest : TIdHTTPRequest;
      oProxy : TIdProxyConnectionInfo;
      oResponse : TIdHTTPResponse;
      iCount : Integer;
  begin
      Memo1.Lines.Clear;
      oProxy := TIdProxyConnectionInfo.Create;
      oProxy.BasicAuthentication := True;
      oProxy.ProxyPassword := '******';
      oProxy.ProxyPort := 8080;
      oProxy.ProxyServer := 'proxy';
      oProxy.ProxyUsername := 'user';
      IdHTTP1.ProxyParams := oProxy;
      IdHTTP1.ReadTimeOut := TrackBar1.Position * 1000; //msec
      Memo1.Lines.Add('**** START ****');
      for iCount := 0 to memToCheck.Lines.Count - 1 do
      begin
          try
              IdHTTP1.Head(memToCheck.Lines[iCount]);
          except
          end;
          oResponse := IdHTTP1.Response;
          Memo1.Lines.Add(Format('Checking:
%s',[memToCheck.Lines[iCount]]));
          Memo1.Lines.Add(Format('..Response: %s (Returncode:
%d)',[IdHTTP1.ResponseText,IdHTTP1.ResponseCode]));
      end;
      Memo1.Lines.Add('**** END ****');
      IdHTTP1.Disconnect;
  end;

Replies