要求用IDHTTP解决,我自己还是搞不定,郁闷了!procedure TForm1.btnLoginClick(Sender: TObject); 
var 
  s, Response: TStringStream; 
  i: Integer; 
begin 
  s := TStringStream.Create(''); 
  Response := TStringStream.Create(''); 
  try 
    s.WriteString('&TPL_username=用户名); 
    s.WriteString('&TPL_password=密码'); 
    s.WriteString('&Submit=登 录'); 
    s.WriteString('&CtrlVersion=1,0,0,7'); 
    s.WriteString('&support=000001'); 
    s.WriteString('&tid='); 
    s.WriteString('&actionForStable=enable_post_user_action'); 
    s.WriteString('&TPL_redirect_url='); 
    s.WriteString('&event_submit_do_login=anything'); 
    s.WriteString('&abtest='); 
    s.WriteString('&pstrong='); 
    s.WriteString('&from='); 
    s.WriteString('&yparam='); 
    s.WriteString('&done='); 
    http.HandleRedirects:=true; 
http.Request.Connection:='Keep-Alive'; 
http.Request.CacheControl:='no-cache'; 
http.Request.Accept:='image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, */*'; 
http.Request.ContentType:= 'application/x-www-form-urlencoded'; 
http.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)'; 
http.Request.host:='member1.taobao.com'; http.Request.Referer:='http://member1.taobao.com/member/login.jhtml'; 
    try 
      http.Post('http://member1.taobao.com/member/login.jhtml', s, Response) 
    except 
      http.Get(http.Response.Location, Response); 
    end; 
    
    //Memo1.Lines.Text:=http.Get('http://auction1.taobao.com/auction/goods/goods_on_sale.htm'); 
    Memo1.Lines.Text := Response.DataString;   finally 
    s.Free; 
    Response.Free; 
  end; end; 

解决方案 »

  1.   


    unit Unit7;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,ComObj,IdHTTP;type
      TForm7 = class(TForm)
        Memo_Log: TMemo;
        Button1: TButton;
        Button2: TButton;
        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.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.试试效果,调试版本:Delphi2007,Indy组件版本:10.2.3
      

  2.   

    大师
    MyRedirect这个函数是做什么用的?
      

  3.   

    是HTTP对象在OnRedirect事件时候的回调