[delphi]indy10 idhttp get方法

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.

Demo下載:

http://download.csdn.net/detail/none01/5128838

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章