我用IdHTTP.post 登录上了一个网站,然后在登录的情况下,访问该网站的其它网页。 我用IdHTTP.post 登录上了一个网站,然后在登录的情况下,访问该网站的其它网页。post返回的值显示登录成功了,但是我访问其它网页时,却发现连接已经断开。请问如何解决。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 POST登陆成功以后取COOKIE访问别的页面时把COOKIE带上 就是在这里怎么才能把访问别的页面时把COOKIE带上 var Param:TStringList; RStream:TStringStream; i:integer;begin Param:=TStringList.Create; RStream:=TStringStream.Create(''); try Param.Add('smsm=ceshi123'); Param.Add('smsxm=ceshi123'); memo1.lines.add(IdHTTP1.Post('http://www.xxxxxxxxxxxxx.com/,Param)); Cookies.Clear; Cookies.lines.add(inttostr(CookieMngr.CookieCollection.Count)); for i := 0 to CookieMngr.CookieCollection.Count - 1 doCookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText);finallyParam.Free;RStream.Free;end;end;然后在访问别的页面就是var Param:TStringList; RStream:TStringStream;begin Param:=TStringList.Create; RStream:=TStringStream.Create(''); Edit2.Text := HTTPEncode(Edit1.Text);//IdHttp1.Request.SetHeaders;// IdHttp1.Request.RawHeaders.Values['Cookie']:='0';//IdHttp1.Request.CustomHeaders.add(Cookies.text); Param.Add('kfgldl=ceshi123'); Param.Add('txtMobileList=xxxxxxxxx'); Param.Add('txtSms=222222'); Param.Add('txtSpli=1'); Param.Add('zhgls=70'); memo2.lines.add(IdHTTP1.Post('http://www.xxxxxxx.com/xxxxxx.asp?',Param));反回<script>alert('温馨小提示:登录超时,请重新登录!');top.location.href='/';</script> 用INDY10吧。有自动保存COOKIE的功能。D7里的INDY9没有此功能。 以get为例,伪造session IdHttp1.Get(mURL1); mStr := IdHttp1.Response.CustomHeaders.Values[ 'Set-Cookie']; if Pos( ';',mStr)> 0 then Session_ID := LeftBStr(mStr,Pos( ';',mStr)-1) else Session_ID := mStr; IdHttp1.Request.CustomHeaders.Add( 'Cookie:' + Session_ID); IdHttp1.Get(mURL2); D7的INDY9 菜鸟求助,Pascal 和C++的对应写法! 如何取得Dbgrid光标所在列的列名? [面对对象开发新手] 请教 destructor 问题以及获得feild值的问题,谢谢。 如何将打印文件到网络打印机上? 新年顺便送分! 获得数据包后,来编假的外挂服务器端如何下手呀 不是高手不要来:串口接受问题?---- 在线等待! 请问delphi中有二~十进制的转换函数吗..... 关于使用quickreport 打印表格,在线。答案正确马上结帖! 关于键盘输入的问题!!! 大虾请入,关于数据表的问题 请问这个效果(动态菜单)该怎么做啊?? 跨进程插入button,关于回调函数怎么写?
访问别的页面时把COOKIE带上
Param:TStringList;
RStream:TStringStream;
i:integer;
begin
Param:=TStringList.Create;
RStream:=TStringStream.Create('');
try
Param.Add('smsm=ceshi123');
Param.Add('smsxm=ceshi123');
memo1.lines.add(IdHTTP1.Post('http://www.xxxxxxxxxxxxx.com/,Param));
Cookies.Clear;
Cookies.lines.add(inttostr(CookieMngr.CookieCollection.Count));
for i := 0 to CookieMngr.CookieCollection.Count - 1 do
Cookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText);
finally
Param.Free;
RStream.Free;end;
end;
然后在访问别的页面就是
var
Param:TStringList;
RStream:TStringStream;
begin
Param:=TStringList.Create;
RStream:=TStringStream.Create('');
Edit2.Text := HTTPEncode(Edit1.Text);
//IdHttp1.Request.SetHeaders;
// IdHttp1.Request.RawHeaders.Values['Cookie']:='0';//IdHttp1.Request.CustomHeaders.add(Cookies.text);
Param.Add('kfgldl=ceshi123');
Param.Add('txtMobileList=xxxxxxxxx');
Param.Add('txtSms=222222');
Param.Add('txtSpli=1');
Param.Add('zhgls=70');
memo2.lines.add(IdHTTP1.Post('http://www.xxxxxxx.com/xxxxxx.asp?',Param));
反回<script>alert('温馨小提示:登录超时,请重新登录!');top.location.href='/';</script>
有自动保存COOKIE的功能。
D7里的INDY9没有此功能。
mStr := IdHttp1.Response.CustomHeaders.Values[ 'Set-Cookie'];
if Pos( ';',mStr)> 0 then
Session_ID := LeftBStr(mStr,Pos( ';',mStr)-1)
else
Session_ID := mStr; IdHttp1.Request.CustomHeaders.Add( 'Cookie:' + Session_ID);
IdHttp1.Get(mURL2);
D7的INDY9