Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   idHTTP Komponente (https://www.delphipraxis.net/187964-idhttp-komponente.html)

strom 19. Jan 2016 20:26

idHTTP Komponente
 
Liste der Anhänge anzeigen (Anzahl: 1)
hallo,

bekomme immer eine Fehlermeldung :-(
was ist hier falsch?

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
 request,content : string;
  i : Integer;
begin
  content := 'type=pocsag&address=1234567&flags=0&function=a&message=hallo1111';
  request := 'POST /telegramin/alarmgeber/input.xml HTTP/1.1';
  idHTTP1.Request.Charset := 'utf-8';
  idHTTP1.Request.BasicAuthentication := true;
  idHTTP1.Request.Username := '******';
  idHTTP1.Request.Password := '******';
  idHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
  idHTTP1.Request.Host := '192.168.0.69';
  idHTTP1.IOHandler.WriteLn(request);
  idHTTP1.IOHandler.WriteLn(request);
   for I := 1 to 20 do
    Memo1.Lines.Add(idhttp1.IOHandler.ReadLn);
   idHTTP1.Disconnect;
end;

geskill 19. Jan 2016 21:23

AW: idHTTP Komponente
 
Hallo strom,

du musst den IOHandler initialisieren:

Delphi-Quellcode:
idHTTP1.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
Ich würde es eher so machen:
Delphi-Quellcode:
var
  params: TStringList;
  request, content, response: string;
  // i: Integer;
begin
  IdHTTP1.request.Charset := 'utf-8';
  IdHTTP1.request.BasicAuthentication := true;
  IdHTTP1.request.Username := '******';
  IdHTTP1.request.Password := '******';
  IdHTTP1.request.ContentType := 'application/x-www-form-urlencoded';
  IdHTTP1.request.Host := '192.168.0.69';

  params := TStringList.Create;
  try
    params.Add('type=pocsag');
    params.Add('address=1234567');
    params.Add('flags=0');
    params.Add('function=a');
    params.Add('message=hallo1111');

    response := IdHTTP1.Post('http://192.168.0.69/telegramin/alarmgeber/input.xml', params); // Hier ist der POST-Request
  finally
    params.Free;
  end;
end;
Mit dem ganz neuen Indy Build wird der IOHandler jetzt auch automatisch initialisiert (ich glaube aber nur wenn man dies über die GET, POST, ... Funktionen abwickelt).

Siehe auch: http://www.delphipraxis.net/160152-i...protokoll.html

EDIT: Ich habe gerade nachgeschaut. Wie ich schon sagte, mit den neuen Indy's wird der IOHandler automatisch erstellt (Typ: TIdSSLIOHandlerSocketBase; siehe: CheckAndConnect()). Dies wird aber erst durch ConnectToHost() und dies durch DoRequest() aufgerufen, welches die ganzen GET, POST, HEAD usw. bündelt. Also allein die Erzeugung der TIdHTTP Komponente reicht nicht aus (was ich schon sagte).


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:37 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz