Const TimeOut: Integer = 30000;
IPVersion: TIdIPVersion = Id_IPv4;
Host:
String = '
123.45.67.89';
Port: Word = 0;
URI:
String = '
/RPC2';
UserAgent:
String = '
himXML-RPC/1.0.0 (WinNT)';
RequestXML:
String = '
<?xml version="1.0"?><methodCall><methodName>examples</methodName></methodCall>';
Var S:
String;
ResponseHeader:
Array of String;
ResponseXML:
String;
ResponseOK: Boolean;
Begin
IdTCPClient1.ConnectTimeout := TimeOut;
IdTCPClient1.ReadTimeout := TimeOut;
IdTCPClient1.IPVersion := IPVersion;
IdTCPClient1.Host := Host;
IdTCPClient1.Port := Port;
IdTCPClient1.Connect;
Try
IdTCPClient1.IOHandler.WriteBufferClear;
IdTCPClient1.IOHandler.WriteBufferOpen;
Try
IdTCPClient1.IOHandler.WriteLn('
POST ' +
URI + '
HTTP/1.0');
IdTCPClient1.IOHandler.WriteLn('
User-Agent: ' + UserAgent);
IdTCPClient1.IOHandler.WriteLn('
Host: ' + Host);
IdTCPClient1.IOHandler.WriteLn('
Content-Type: text/xml');
IdTCPClient1.IOHandler.WriteLn('
Content-length: ' + IntToStr(Length(RequestXML)));
IdTCPClient1.IOHandler.WriteLn;
IdTCPClient1.IOHandler.
Write(RequestXML);
IdTCPClient1.IOHandler.WriteBufferFlush;
IdTCPClient1.IOHandler.WriteBufferClose;
Except
IdTCPClient1.IOHandler.WriteBufferCancel;
Raise;
End;
ResponseHeader :=
nil;
Repeat
S := IdTCPClient1.IOHandler.ReadLn(enUTF8);
If Trim(S) = '
'
Then Break;
SetLength(ResponseHeader, Length(ResponseHeader) + 1);
ResponseHeader[High(ResponseHeader)] := S;
Until not IdTCPClient1.Connected;
ResponseXML := IdTCPClient1.IOHandler.AllData(enUTF8);
If Assigned(ResponseHeader)
Then S := ResponseHeader[0]
Else S := '
';
S := Trim(Copy(S, Pos('
', S) + 1, Length(S)));
S := Trim(Copy(S, 1, Pos('
', S) - 1));
ResponseOK := (Trim(ResponseXML) <> '
')
and (S = '
200');
Finally
IdTCPClient1.Disconnect;
End;
End;