DELPHI7 IDHTTP POST登陆3GQQ网站
用HTTPWATCH监测登陆http://www.中登陆过程,其POST数据为:POST /dir/pt.3g. HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*
Referer: http://www.
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) )
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: www.
Content-Length: 334
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: transfer=1; auto_proxy=1; cookies=1; mobile=0; cnzz_a30046588=19; sin30046588=none; rtime30046588=0; ltime30046588=1311690057188; cnzz_eid30046588=43887365-1311676841-; PHPSESSID=ec2ee636feb1da101eb71e60b4ced904; c[3g.][/][aW5mb19pbmRleF9hdHQ%3D]=1; c[3g.][/][M2dfbGFzdExvZ2luUXE%3D]=6506507; c[3g.][/][cHRfa3NpZGxz]=8e2a78761834fe9d4ab8885fad311d5e
sid=AcCEzXiVWDXg1O8tT8rr6PCr&qq=6506507&pwd=a42podr8&bid_code=3GQQ&toQQchat=true&login_url=http%3A%2F%2Fpt.3g.
我用DELPHI7写如下代码:
procedure TForm1.Button1Click(Sender: TObject);
var
TmpStr,sid,r:string; i,p:integer; info:Tstrings;res:Tstringstream;
begin
i:=1;
TmpStr:=idhttp1.Get('http://www.');
memo1.Clear;
memo1.Text:=tmpstr;
p:= Pos('sid=', TmpStr) + Length('sid='); //取得SID
TmpStr := Copy(TmpStr, p, Length(TmpStr));
p := Pos('&', TmpStr);
sid:=trim(copy(TmpStr, 1, P - 1));
tmpstr:=idhttp1.Get('http://www.'+sid);
p:= Pos('handleLogin?r=', TmpStr) + Length('handleLogin?r='); //取得登陆时候的NO
TmpStr := Copy(TmpStr, p, Length(TmpStr));
p := Pos('" method', TmpStr);
r:=trim(copy(TmpStr, 1, P - 1));
info:=tstringlist.Create;
res:=tstringstream.Create('');
info.Add('sid='+sid+'&qq=6506507&pwd=a42podr8&bid_code=3GQQ&toQQchat=true&login_url=http://info50.3g.');
with IdHTTP1 do
begin
Request.SetHeaders;
HandleRedirects:=true;
Request.Connection:='Keep-Alive';
request.UserAgent:='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) )';
request.CacheControl:='no-cache';
request.Accept:='image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*';
request.Referer:='http://www.'+sid;
request.Host:='www.';
HTTPOptions:=HTTPOptions+[hoKeepOrigProtocol];
try
post('http://www.'+r,info,res);
memo1.Lines.Text:=Utf8ToAnsi(res.DataString);
// Disconnect;
info.Free;
res.Free;
except
// Disconnect;
info.Free;
res.Free;
end;
end;
end;
结果在MEMO1里显示:
<p align="center">手机腾讯网</p>
<p align="center">
QQ号码不能为空,请输入您要登录的QQ号码
</p>
<p>
<a href="javascript:wap_prev()">返回上一页</a>
</p>
<p><a href="http://www.手机腾讯网</a>-<a href="http://www.导航</a>-<a href="http://www.软件</a>-<a href="http://www.
请问我这个提交问题出在哪?