如何让idhttp直接使用ie登录好的cookie来工作

来源:互联网 发布:java html压缩成一行 编辑:程序博客网 时间:2024/04/30 03:54

原文:http://topic.csdn.net/t/20050620/16/4094632.html

说清楚一点问题,我想让用户通过ie登录一个网站后,然后程序工作,通过idhttp直接取到ie中用户的cookie然后来工作,这样我程序里就不需要重新通过idhttp来登录网站了;不知道有没有可能实现?
最好能有点调试代码或者思路,谢谢了!//简单点来说,就是使用Cookies登陆网页;吐舌头

 

答:

我发现一个问题,就是当ie登录记住cookie后,ie再次登录可以直接访问,用webbrowser也可以直接访问,但是当用idhttp     get的时候,出现的就是需要登录的界面,为什么idhttp不能继承ie的cookie,而webbrowser可以呢?

 

uses
    ...,   WinInet;


function   CanGetIECookie(const   URL:   string;   var   Cookie:   string):   boolean;
var
    lpvBuffer:   array[0..1000]   of   byte;
    lpdwBufferLength:   cardinal;
begin
    lpdwBufferLength   :=   sizeof(lpvBuffer);
    result   :=   InternetGetCookie(PChar(URL),   nil,   @lpvBuffer,   lpdwBufferLength);
    if   result   then
        Cookie   :=   pchar(@lpvBuffer);
end;


if   CanGetIECookie(url,   str)   then
begin
    CookieStr   :=   'Cookie:   '   +   str;
    idHttp1.Request.CustomHeaders.Text   :=   CookieStr;
    Memo1.Lines.Text   :=   IdHTTP1.Get(WebSite);
end;