为什么用idhttp登陆淘宝网站,都是返回首页,登陆不了?

ajmxj 2009-02-08 11:55:59
要求用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;

...全文
308 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hidelphi 2009-02-09
  • 打赏
  • 举报
回复

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 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
ajmxj 2009-02-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hidelphi 的回复:]
正在想办法解决,我试试
[/Quote]
辛苦大师了
hidelphi 2009-02-09
  • 打赏
  • 举报
回复
正在想办法解决,我试试
hidelphi 2009-02-09
  • 打赏
  • 举报
回复
是HTTP对象在OnRedirect事件时候的回调
ajmxj 2009-02-09
  • 打赏
  • 举报
回复
大师
MyRedirect这个函数是做什么用的?

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧