DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: KfnqDuxw
今日帖子: 29
在线用户: 26
导航: 论坛 -> Web应用开发 斑竹:bodies  
作者:
男 wplgm (wplgm) ★☆☆☆☆ -
普通会员
2014/5/14 11:14:45
标题:
idhttp自动登录成功,但返回的页面还是未登录的页面 浏览:1953
加入我的收藏
楼主: procedure TForm1.Button1Click(Sender: TObject);
  const
  sPostUrl= 'http://www.iwpai.com/login/index.html';
var
  postcmd : TStringList;
  code:string;
  done: Boolean;
begin
  try
  idhttp1.CookieManager:=idcookiemanager1;
  postcmd := TStringList.Create;
  postcmd.Add('userID=' + Edit1.Text);
  postcmd.Add('userLoginPass=' + Edit2.Text);
  postcmd.Add('yzmTextBox=' + Edit3.Text);
  Memo1.Text :=IdHTTP1.Post(sPostUrl, postcmd); 
  showmessage('OK');
  except
   showmessage('NO');
  end;
    code := (IdHTTP1.Get('http://www.iwpai.com/ucacc/index.html'));
    Memo1.Clear;
    Memo1.lines.Add(code);
  postcmd.Free;
end;

我这样登录后,get返回来的还是未登录成功,这是怎么回事?
----------------------------------------------
-
作者:
男 oloveuxyz (oloveuxyz) ★☆☆☆☆ -
普通会员
2014/5/14 12:14:43
1楼: 可能是Cookie的问题
加一个CookieManager试试
----------------------------------------------
什么都没写~~~
作者:
男 pankangkang (aaaa) ★☆☆☆☆ -
普通会员
2014/5/14 12:40:02
2楼: 你要根据 登陆后返回的header 执行 模拟cookie
参考以下代码
function TMaindlg.GetCookie: string;
var
  i:Integer;
  tmp,cookie:string;
begin
   for i := 0 to idhtp1.Response.RawHeaders.Count - 1 do
   begin
      tmp := idhtp1.Response.RawHeaders[i];
      if pos('set-cookie: ', LowerCase(tmp)) = 0 then Continue;
      tmp := Trim(Copy(tmp, Pos('Set-cookie: ', tmp) + Length('Set-cookie: '), Length(tmp)));
      tmp := Trim(Copy(tmp, 0, Pos(';', tmp) - 1));
      if cookie = '' then cookie := tmp else cookie := cookie + '; ' + tmp;
  end;
  Result := cookie;
end;

procedure TMaindlg.Setcookie;
var
   i: Integer;
   tmp, cookie: String;
begin
   cookie := GetCookie;
  if cookie <> '' then
  begin
    for i := 0 to idhtp1.Request.RawHeaders.Count - 1 do
    begin
      tmp := idhtp1.Request.RawHeaders[i];
      if Pos('cookie', LowerCase(tmp)) = 0 then Continue;
      idhtp1.Request.RawHeaders.Delete(i);
      Break;
    end;
    idhtp1.Request.RawHeaders.Add('cookie: ' + cookie);
    idhtp1.Request.CustomHeaders.Add('Cookie:' + cookie);
  end;
end;
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行570.3125毫秒 RSS