delphi发送http请求示例(THttpCli组件示例)

//发送请求

procedure TfrmMain.LocateExecute(Sender: TObject);
var
fFileInStream:TFileStream;
fStreamIn:TStringStream;
begin
fFileInStream:
= TFileStream.Create( ' c:\request.xml ' ,fmOpenRead);
fStreamIn :
=  TStringStream.Create( '' );
fStreamIn.CopyFrom(fFileInStream,fFileInStream.Size);

try
HttpCli.SendStream :
=  TStringStream.Create(fStreamIn.DataString);
HttpCli.RcvdStream :
=  TStringStream.Create( '' );

HttpCli.PostASync;
//  MmoResponse.Text:='Request Finished,waiting for response...';
fFileInStream.Free;
fStreamIn.Free;
except
on e:Exception 
do
begin
ShowMessage(
' Exception Msg: ' +  e.Message );
Exit;
end;
end;
end;

 

//收到回应

procedure TfrmMain.HttpCliRequestDone(Sender: TObject; RqType: THttpRequest;
ErrCode: Word);
var
varStream:TStringStream;
begin
varStream:
= TStringStream.Create( '' );
varStream:
= TStringStream(HttpCli.RcvdStream);
varStream.Seek(
0 , soFromBeginning);
XML.LoadFromStream( varStream );
MmoResponse.Lines :
=  XML.XML;
end;

你可能感兴趣的:(Delphi,XML,C,C++,C#)