Autor Beitrag
Experience1986
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 192

Win XP Pro SP2
Delphi 7
BeitragVerfasst: Mo 27.02.06 21:58 
Hi,

ich nutze folgenden Code, um mit der Indy-Komponente TidHTTP Daten an ein PHP-Script zu senden:

ausblenden volle Höhe 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:
41:
42:
function SendPostData(Ahttp: TIdHTTP; const AtoURL: Stringconst aParams: TStrings): String;
  //Ahttp: Die HTTP Komponente von Indy 8.0 bzw. 9.0
  //AtoURL: An diese URL werden die Informationen gesendet
  //Result: HTML-Ergebnis (Antwort des Scripts)
Var
  lStream: TMemoryStream; //HTML-Result des PHP-Scripts
  lParams: TStringStream;
  I: Integer;
begin
  Result:='';

  if not EnableInternetProcesses then exit;

  if not Assigned(aHttp) then
    exit;
  lStream := TMemoryStream.create;
  lParams := TStringStream.create('');
  try
    Ahttp.AllowCookies:=true;
    AHTTP.Request.ContentType := 'application/x-www-form-urlencoded';

    //Dieser Stream wird letztendlich gesendet
    //Stream mit Werten füllen
    for I:=0 to aParams.Count-1 do
      lParams.WriteString(aParams[I] + '&');

    try
      //Stream an das PHP-Script senden
      AHTTP.Post(AtoURL,
                 lParams,
                 lStream);
    except

    end;
    SetLength(Result,lStream.Size);
    lStream.Position:=0;
    lStream.ReadBuffer(Result[1],lStream.Size);
  finally
    lParams.Free;
    lStream.Free;
  end;
end;


Besteht nun aber keine Internet-Verbindung bzw. stimmt mit der Adressierung des Scriptes etwas nicht, so Stoppt die gesamte Anwendung bis der HTTP-Timeout erfolgt.

Kann man diesen Stopp umgehen? Wenn nicht, wie kann man den HTTP-Timeout verkürzen?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 28.02.06 02:40 
Vielleicht hilft es, das ganze in einen Thread auszulagern.
Wobei das aber vielleicht overkill ist.

Den TimeOut kannste im Objektinspektor von idHTTP ändern.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Experience1986 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 192

Win XP Pro SP2
Delphi 7
BeitragVerfasst: Di 28.02.06 02:44 
In wie fern auslagern? in eine DLL oder in eine seperate EXE?

Wenn ich die Eigenschaft Timeout ändere, scheint idHTTP das nicht so wirklich zu übernehmen, sprich, ist keine Internet vorhanden, so brauch die Komponente immer noch ewig.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 28.02.06 02:55 
ausblenden volle Höhe 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:
41:
42:
43:
type
  TMainForm = class(TForm)
    [...]
  private
    Info: TThread;
  end;

  TInfo = class(TThread)
  protected  
    procedure Execute; override;  
  end;

  [...]

implementation

  [...]

procedure TInfo.Execute;
begin
  // Tue irgendwas

  Terminate;
end;

  [...]

procedure TMainForm.FormShow(Sender: TObject);
begin
  if not Assigned(Info) then
  begin
    Info := TInfo.Create(True);
    with Info do
    begin
      FreeOnTerminate := True;
      Resume;
    end;
  end;
end;

  [...]

end.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Experience1986 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 192

Win XP Pro SP2
Delphi 7
BeitragVerfasst: Di 28.02.06 15:39 
Danke... Abe rin wie fern könnte das zum overkill werden?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 28.02.06 19:09 
Die Frage ist, obs net ne bessere Möglichkeit gibt.
Weil wegen ner kleinen Abfrage gleich nen ganzen Thread benutzen :?

Hast du es mal mit IdAntiFreeze von Indy probiert? Vielleicht geht das ja.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Experience1986 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 192

Win XP Pro SP2
Delphi 7
BeitragVerfasst: Di 28.02.06 21:30 
Und wie kann ich diese Nutzen?
Muss ich die idHTTP denn damit "verbidnen"?

Und was steckt hinter der idAntiFreeze