[delphi]indy10 idhttp get方法

来源:互联网 发布:淘宝网货源怎么找 编辑:程序博客网 时间:2024/05/16 14:33

idhttp中对于get方法的定义:

[delphi] view plaincopyprint?
  1. procedure Get(AURL: string; AResponseContent: TStream); overload;  
  2. procedure Get(AURL: string; AResponseContent: TStream; AIgnoreReplies: array of SmallInt);  
  3.  overload;  
  4. function Get(AURL: string): string; overload;  
  5. function Get(AURL: string; AIgnoreReplies: array of SmallInt): string; overload;  

其中的最基本的方法是过程类方法
[delphi] view plaincopyprint?
  1. procedure Get(AURL: string; AResponseContent: TStream; AIgnoreReplies: array of SmallInt);  
  2.      overload;  
其他的几个get方法重载都是基于嵌套的此方法。

参数:

[python] view plaincopyprint?
  1. AURL: string;   // get操作的目标URL  
  2. AResponseContent: TStream;  // 返回流  
  3. AIgnoreReplies: array of SmallInt;  // 忽略掉出现这些http状态码的错误  

示例代码:

[delphi] view plaincopyprint?
  1. unit UMain;  
  2.   
  3. interface  
  4.   
  5. uses  
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  7.   Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,  
  8.   IdHTTP, StdCtrls;  
  9.   
  10. type  
  11.   TForm1 = class(TForm)  
  12.     IdHTTP1: TIdHTTP;  
  13.     Memo1: TMemo;  
  14.     btnGetOne: TButton;  
  15.     btnGetTwo: TButton;  
  16.     btnGetThree: TButton;  
  17.     btnGetFour: TButton;  
  18.     procedure btnGetOneClick(Sender: TObject);  
  19.     procedure btnGetTwoClick(Sender: TObject);  
  20.     procedure btnGetThreeClick(Sender: TObject);  
  21.     procedure btnGetFourClick(Sender: TObject);  
  22.   private  
  23.     { Private declarations }  
  24.   public  
  25.     { Public declarations }  
  26.   end;  
  27.   
  28. var  
  29.   Form1: TForm1;  
  30.   
  31. implementation  
  32.   
  33. {$R *.dfm}  
  34.   
  35. const  
  36.   Cgeturl = 'http://www.soso.com/';  
  37.   C302url = 'http://soso.com/';  
  38.   
  39. var  
  40.   RespData : TStringStream;  
  41.   
  42. procedure TForm1.btnGetOneClick(Sender: TObject);  
  43. begin  
  44.   RespData := TStringStream.Create('');  
  45.   IdHTTP1.Get(Cgeturl, RespData);  
  46.   Memo1.Text := RespData.DataString;  
  47. end;  
  48.   
  49. procedure TForm1.btnGetTwoClick(Sender: TObject);  
  50. begin  
  51.   RespData := TStringStream.Create('');  
  52.   IdHTTP1.Get(C302url, RespData, [302]);  
  53.   Memo1.Text := RespData.DataString;  
  54. end;  
  55.   
  56. procedure TForm1.btnGetThreeClick(Sender: TObject);  
  57. begin  
  58.   Memo1.Text := IdHTTP1.Get(Cgeturl);  
  59. end;  
  60.   
  61. procedure TForm1.btnGetFourClick(Sender: TObject);  
  62. begin  
  63.   Memo1.Text := IdHTTP1.Get(C302url, [302]);  
  64. end;  
  65.   
  66. end.  
0 0