idhttp中对于get方法的定义:
procedure Get(AURL: string; AResponseContent: TStream); overload; procedure Get(AURL: string; AResponseContent: TStream; AIgnoreReplies: array of SmallInt); overload; function Get(AURL: string): string; overload; function Get(AURL: string; AIgnoreReplies: array of SmallInt): string; overload;
其中的最基本的方法是过程类方法
procedure Get(AURL: string; AResponseContent: TStream; AIgnoreReplies: array of SmallInt); overload;其他的几个get方法重载都是基于嵌套的此方法。
AURL: string; // get操作的目标URL AResponseContent: TStream; // 返回流 AIgnoreReplies: array of SmallInt; // 忽略掉出现这些http状态码的错误示例代码:
unit UMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls; type TForm1 = class(TForm) IdHTTP1: TIdHTTP; Memo1: TMemo; btnGetOne: TButton; btnGetTwo: TButton; btnGetThree: TButton; btnGetFour: TButton; procedure btnGetOneClick(Sender: TObject); procedure btnGetTwoClick(Sender: TObject); procedure btnGetThreeClick(Sender: TObject); procedure btnGetFourClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} const Cgeturl = 'http://www.soso.com/'; C302url = 'http://soso.com/'; var RespData : TStringStream; procedure TForm1.btnGetOneClick(Sender: TObject); begin RespData := TStringStream.Create(''); IdHTTP1.Get(Cgeturl, RespData); Memo1.Text := RespData.DataString; end; procedure TForm1.btnGetTwoClick(Sender: TObject); begin RespData := TStringStream.Create(''); IdHTTP1.Get(C302url, RespData, [302]); Memo1.Text := RespData.DataString; end; procedure TForm1.btnGetThreeClick(Sender: TObject); begin Memo1.Text := IdHTTP1.Get(Cgeturl); end; procedure TForm1.btnGetFourClick(Sender: TObject); begin Memo1.Text := IdHTTP1.Get(C302url, [302]); end; end.