最近在写一个登陆淘宝网店下载订单的程序,看了有关用idhttp登陆淘宝的帖子,多次尝试,还是未遂。1、idhttp.get('http://member1.taobao.com/member/login.jHTML?TPL_username=用户名&TPL_password=密码&Submit=登 录&actionForStable=enable_post_user_action&action=Authenticator&TPL_redirect_url=&event_submIT_do_login=anything&abtest=&pstrong=1&from=');
出现异常消息:HTTP/1.1 302 Found2、如下程序,返回登陆页面
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; 3、“hidelphi”老兄说解决了这个问题,提供了一段程序,但是最关键的“加密后”不知道怎么实现的(http://topic.csdn.net/u/20090208/23/1614995e-0017-4475-b884-95512e96278f.html)
unit Unit7;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ComObj;type
  TForm7 = class(TForm)
    Memo_Log: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form7: TForm7;implementation{$R *.dfm}function ADOStreamDecode(const S:Variant):string;
var
  Obj:OleVariant;
begin
  Obj:=CreateOleObject('Adodb.Stream');
  try
    Obj.Type :=1;
    Obj.Mode :=3;
    Obj.Open;
    Obj.Write(S);
    Obj.Position:= 0;
    Obj.Type := 2;
    Obj.Charset :='GB2312';
    Result := Obj.ReadText;
  finally
    Obj.Close;
    Obj:=Unassigned;
  end;
end;procedure TForm7.Button1Click(Sender: TObject);
var
  FHTTPObj:OleVariant;
  _PostStr:OleVariant;
begin
  FHTTPObj:=CreateOleObject('WinHttp.WinHttpRequest.5.1');
  try
    _PostStr:='TPL_username=用户名&CtrlVersion=1,0,0,7&support=000001&'+
    'tid=加密后的&'+
    'TPL_password=加密后的&'+
    'actionForStable=enable_post_user_action&action=Authenticator&'+
    'TPL_redirect_url=&event_submit_do_login=anything&abtest=&pstrong=&'+
    'from=&yparam=&done=';
    //FHTTPObj.Option(6):=0;//禁止Location
    FHTTPObj.setTimeouts(10000,10000,10000,10000);
    FHTTPObj.Open('POST', 'http://member1.taobao.com/member/login.jhtml', False);
    FHTTPObj.SetRequestHeader('Content-Type','application/x-www-form-urlencoded');
    FHTTPObj.SetRequestHeader('Content-Length',Length(_PostStr));
    FHTTPObj.send(_PostStr);
    Memo_Log.Text:=ADOStreamDecode(FHTTPObj.ResponseBody);
  finally
    FHTTPObj:=Unassigned;
  end;
end;end.请高人指点,多谢

解决方案 »

  1.   

    借用zhouzuoji兄的代码,用WebBrowsweruses
       SHDocVw, MSHTML, OleCtrls;procedure Taobao_Login(Browser: TWebBrowser;UserName,Password:string);
    var
      Doc:IHTMLDocument2;
      PasswordObj:IHTMLObjectElement;
      V:OleVariant;
    begin
      Browser.Navigate('http://member1.taobao.com/member/login.jhtml');
      while Browser.ReadyState<>4 do
        Application.ProcessMessages;
      Doc:=Browser.Document as IHTMLDocument2;
      (Doc.all.item('TPL_username',varEmpty) as IHTMLInputElement).value:=UserName;
      PasswordObj:=Doc.all.item('Password_Edit',varEmpty) as IHTMLObjectElement;
      V:=PasswordObj.object_;
      v.PasswordMode:=True;
      v.SecurityMode:=False;
      V.TextData:=Password;
      (Doc.all.item('Submit',varEmpty) as IHTMLElement).Click;
    end;
      

  2.   

    多谢英雄,俺家穷,只有这么点米,全给你了。用idhttp可以吗,那个加密是怎么弄的?如果不方便说,等我有分了再提问。