您的位置:首页 > 理论基础 > 计算机网络

[delphi]indy10 idhttp get方法

2014-12-19 12:50 169 查看
idhttp中对于get方法的定义:

[delphi] view
plaincopyprint?

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;

其中的最基本的方法是过程类方法

[delphi] view
plaincopyprint?

procedure Get(AURL: string; AResponseContent: TStream; AIgnoreReplies: array of SmallInt);

overload;

其他的几个get方法重载都是基于嵌套的此方法。

参数:

[python] view
plaincopyprint?

AURL: string; // get操作的目标URL

AResponseContent: TStream; // 返回流

AIgnoreReplies: array of SmallInt; // 忽略掉出现这些http状态码的错误

示例代码:

[delphi] view
plaincopyprint?

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: