Entwickler-Ecke

Internet / Netzwerk - Problem mit IdHTTP.Get


sPeeD2k5 - Mo 04.12.06 22:30
Titel: Problem mit IdHTTP.Get

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Windows,Classes,IdHTTP, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;




var
i,j:integer;
http1 : TIdHTTP;
stream : TFileStream;
IP,Pfad,results :TStringList;

begin
stream:=TFileStream.Create('bla.txt', fmCreate); //Streamerzeugung
http1:=TIDHTTP.Create(nil); //IdHTTP wird erzeugt
IP:=TStringList.Create;   //Stringliste wird erzeugt
Pfad:=TStringList.Create; //Stringliste wird erzeugt

  for i := 1 to ParamCount do
    if ParamStr(i) = '-pma' then     //wenn pma
      begin
      try
        IP.LoadFromFile('hosts.txt');  //IP laden
        Pfad.LoadFromFile('path.txt'); //Path laden
        for j := 1 to IP.Count-1 do
         http1.Get('http://'+IP[j]+Pfad[j]+'main.php',stream);
          WriteLn('http://'+IP[j]+Pfad[j]+'main.php');
      finally
         IP.Free;
         Pfad.Free;
         stream.Free;
        end;
        end;
WriteLn(Paramstr(1));

end.


nun zu meinem problem: wenn ich die exe starte, stürzt sie sofort ab und dann kommt folgende Fehlermeldung:

Exception EStringListError in module Project1.exe at 00014BE1.
List index out of bounds (2147348480).

Hat jemand ne Idee worans liegt? Bin ratlos :/


Narses - Mo 04.12.06 22:35

Moin!


Delphi-Quelltext
1:
for j := 1 to IP.Count-1 do                    

Stringlisten fangen bei 0 an. ;)

Du verwendest relative Pfade, das ist potentiell tödlich... :?

cu
Narses


JayEff - Mo 04.12.06 22:36

Ich würde raten, dass es nicht so einfach ist, ohne Parent ein TidHTTP zu integrieren oder sonst was derartiges. wie auhc immer. wenn du nur eine datei runterladen willst (mit TidHTTP.Get z.B. ) dann benutze
Suche in: Delphi-Forum, Delphi-Library URLDOWNLOADTOFILE (urlmon einbinden)


sPeeD2k5 - Mo 04.12.06 23:05

also ich will jetzt mir den Header ausgeben lassen!


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
try
        IP.LoadFromFile('hosts.txt');  //IP laden
        Pfad.LoadFromFile('path.txt'); //Path laden
        for j := 0 to IP.Count-1 do
         //http1.get('http://'+IP[j]+Pfad[j]+'main.php',stream);
          WriteLn('http://'+IP[j]+Pfad[j]+'main.php');
         http1.head('http://'+IP[j]+Pfad[j]+'main.php');


wollte jetzt mit Stream.Add(http1.ResponseText); mir den Header ausgeben lassn, aber das funktioniert nicht? was is daran falsch? mit Get hats ja auch geklappt