Einzelnen Beitrag anzeigen

Benutzerbild von Garfield
Garfield

Registriert seit: 9. Jul 2004
Ort: Aken (Anhalt-Bitterfeld)
1.334 Beiträge
 
Delphi XE5 Professional
 
#1

TcpClient - Antwort XML unvollständig.

  Alt 14. Jan 2011, 22:09
Mit Tcpclient wird an die Fritzbox diese Nachricht geschickt:
Code:
POST /upnp/control/WANIPConn1 HTTP/1.1
Host: fritz.box:49000
Accept: */*
Content-Type: text/xml
SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#GetStatusInfo
Content-Length: 263

<?xml version="1.0"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<u:GetStatusInfo xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" />
</s:Body>
</s:Envelope>
Mit diesem Code
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  TcpClient1 : TTcpClient;
begin
  TcpClient1 := TTcpClient.Create(nil);
  TcpClient1.RemoteHost := Edit1.Text;
  TcpClient1.RemotePort := Edit2.Text;
  TcpClient1.OnReceive := TcpReceive;
  TcpClient1.OnError := TcpError;

  TcpClient1.Connect;

  try
    TcpClient1.Sendln(Memo2.Text);
  finally
    TcpClient1.Disconnect;
  end;

  TcpClient1.Destroy;
end;

procedure TForm1.TcpReceive(Sender: TObject; Buf: PAnsiChar; var DataLen: Integer);
begin
  Memo1.Lines.Add(Buf);
end;

procedure TForm1.TcpError(Sender: TObject; SocketError: Integer);
begin
  ShowMessage(Format('Fehler: %d', [SocketError]));
end;
erhalte ich als Ergebnis:
Code:
HTTP/1.1 200 OK
DATE: Fri, 14 Jan 2011 21:51:41 GMT
SERVER: FRITZ!Box Fon WLAN 7320 UPnP/1.0 AVM FRITZ!Box Fon WLAN 7320 (UI) 100.04.88
CONNECTION: keep-alive
CONTENT-LENGTH: 430
CONTENT-TYPE: text/xml; charset="utf-8"
EXT:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>
<u:GetStatusInfoResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewConnectionStatus>Connected</NewConne
Da fehlt leider etwas.

Man kann SendLn und ReceiveLn so oft aufrufen bis die Datei vollständig ist. Das sieht dann so aus:
Code:
HTTP/1.1 200 OK
DATE: Fri, 14 Jan 2011 22:02:45 GMT
SERVER: FRITZ!Box Fon WLAN 7320 UPnP/1.0 AVM FRITZ!Box Fon WLAN 7320 (UI) 100.04.88
CONNECTION: keep-alive
CONTENT-LENGTH: 430
CONTENT-TYPE: text/xml; charset="utf-8"
EXT:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>
<u:GetStatusInfoResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewConnectionStatus>Connected</NewConnectionStatus>
<NewLastConnectionError>ERROR_NONE</NewLastConnectionError>
<NewUptime>35312</NewUptime>
</u:GetStatusInfoResponse>
</s:Body> </s:Envelope>HTTP/1.1 200 OK
Was mache ich falsch? Es muss doch möglich sein, die ganze Datei sofort mit einem Aufruf zu erhalten?
Angehängte Dateien
Dateityp: 7z Project.7z (178,2 KB, 16x aufgerufen)
Gruss Garfield
Ubuntu 22.04: Laz2.2.2/FPC3.2.2 - VirtBox6.1+W10: D7PE, DXE5Prof
  Mit Zitat antworten Zitat