用idhttp登陆淘宝网站

来源:互联网 发布:avi视频下载软件 编辑:程序博客网 时间:2024/04/30 12:05

unit Unit7;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ComObj,IdHTTP;

type
  TForm7
= class(TForm)
    Memo_Log: TMemo;
    Button1: TButton;
    Button2: TButton;
   
procedure Button1Click(Sender: TObject);
   
procedure Button2Click(Sender: TObject);
  private
   
procedure MyRedirect(Sender: TObject; var dest: string; var NumRedirect: Integer; var Handled: boolean; var VMethod: TIdHTTPMethod);
   
{ Private declarations }
  public
   
{ Public declarations }
 
end;

var
  Form7: TForm7;

implementation

{$R *.dfm}

procedure TForm7.Button1Click(Sender: TObject);
begin
end;

procedure TForm7.Button2Click(Sender: TObject);
var
  PS:TStringList;
  RS,RS1:TStringStream;
  FHTTP:TIdHTTP;
begin
  PS:
=TStringList.Create;
  RS:
=TStringStream.Create('');
  RS1:
=TStringStream.Create('');
  FHTTP:
=TIdHTTP.Create(nil);
  try
    FHTTP.HandleRedirects:
=False;
    FHTTP.OnRedirect:
=MyRedirect;
    FHTTP.Request.UserAgent:
='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
    FHTTP.Request.ContentType:
='application/x-www-form-urlencoded; Charset=UTF-8';
    FHTTP.Request.Host:
='member1.taobao.com';
    FHTTP.Request.Connection:
='Keep-Alive';
    FHTTP.Request.Accept:
='*/*';
    PS.Add(
'TPL_username=用户名');
    PS.Add(
'CtrlVersion=1,0,0,7');
    PS.Add(
'support=000001');
    PS.Add(
'tid=加密后');
    PS.Add(
'TPL_password=加密后');
    PS.Add(
'actionForStable=enable_post_user_action');
    PS.Add(
'action=Authenticator');
    PS.Add(
'TPL_redirect_url=');
    PS.Add(
'event_submit_do_login=anything');
    PS.Add(
'abtest=');
    PS.Add(
'pstrong=');
    PS.Add(
'from=');
    PS.Add(
'yparam=');
    PS.Add(
'done=');
    FHTTP.Request.ContentLength:
=Length(PS.Text);
    FHTTP.Post(
'http://member1.taobao.com/member/login.jhtml',PS,RS);
    FHTTP.Get(
'http://my.taobao.com/mytaobao/home/my_taobao.jhtml',RS1);
    Memo_Log.Text:
=RS1.DataString;
  finally
   
if Assigned(FHTTP) then FreeAndNil(FHTTP);
   
if Assigned(PS) then FreeAndNil(PS);
   
if Assigned(RS) then FreeAndNil(RS);
   
if Assigned(RS1) then FreeAndNil(RS1);
 
end;
end;

procedure TForm7.MyRedirect(Sender: TObject; var dest: string;
 
var NumRedirect: Integer; var Handled: boolean; var VMethod: TIdHTTPMethod);
begin
  Handled:
=True;
end;

end.