频道分类

delphi IDHTTP读取网页重定向

作者:admin 来源: 日期:2020/4/3 7:26:05 人气: 标签:

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, StdCtrls, IdIntercept;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure IdHTTP1Status(ASender: TObject; const AStatus: TIdStatus;
      const AStatusText: String);
    procedure IdConnectionIntercept1Receive(
      ASender: TIdConnectionIntercept; AStream: TStream);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
        mstr: string;
        idHttp1: TIdHttp;
        IdConnectionIntercept1: TIdConnectionIntercept;
begin
        Memo1.Lines.Clear;
        idHttp1 := TIdHttp.Create(nil);
        IdConnectionIntercept1 := TIdConnectionIntercept.Create(nil);
        IdConnectionIntercept1.OnReceive := IdConnectionIntercept1Receive;
        idHttp1.Intercept := IdConnectionIntercept1;
        try
                mstr := IdHttp1.Get(Edit1.Text);
        except
        end;
        IdConnectionIntercept1.Destroy;
        idHttp1.Destroy;
end;

procedure TForm1.IdHTTP1Status(ASender: TObject; const AStatus: TIdStatus;
  const AStatusText: String);
begin
        Memo1.Lines.Add(AStatusText)
end;

procedure TForm1.IdConnectionIntercept1Receive(
  ASender: TIdConnectionIntercept; AStream: TStream);
var ss: TStringList;
begin
        Memo1.Lines.Add('------');
        ss := TStringList.Create;
        ss.LoadFromStream(AStream);
        Memo1.Lines.AddStrings(ss);
end;

end.

https://bbs.csdn.net/topics/380146084