多春鱼小屋

登录
记住密码
  1. 首页
  2. 将webbrowser的cookie给idhttp用
将webbrowser的cookie给idhttp用
发布 | 2017-10-17 | 评论数:0 | 阅读数:35759 | 标签:Delphi

网上搜索出来的方法是:Cookie:='Cookie:' +(Web.document as IHtmlDocument2).cookie;

但听说这个方法不能获取全部的Cookie内容,需要借助wininet.dll才可以获取完整。

function GetCookie(url: string): string;

const
  INTERNET_COOKIE_HTTPONLY     = $00002000;
  INTERNET_COOKIE_THIRD_PARTY  = $00000010;
  INTERNET_FLAG_RESTRICTED_ZONE= $00020000;
var
  hModule:THandle;
  InternetGetCookieEx:function(lpszUrl, lpszCookieName,lpszCookieData: PChar; var lpdwSize: DWORD;dwFlags:DWORD;lpReserved: Pointer): BOOL;StdCall;
  CookieSize:DWORD;
  cookiedata:PWideChar;
  thebool:bool;
begin
  result := '';
  hModule:=GetModuleHandle('wininet.dll');
  if hModule<>0 then
  begin
    @InternetGetCookieEx:=GetProcAddress(hModule,'InternetGetCookieExW');
    if @InternetGetCookieEx<>nil then
    begin
      CookieSize:=10240;
      Cookiedata := AllocMem(CookieSize);
      thebool:=InternetGetCookieEx(PWideChar(url),nil,CookieData,CookieSize,INTERNET_COOKIE_HTTPONLY,nil);
      if thebool then result := CookieData;
      FreeMem(Cookiedata);
    end;
    FreeLibrary(hModule);
  end;
end;

分享至:

本文已关闭评论

  • 评论0
  • 粉丝1
  • 文章33

    • 多春鱼
    • 广州
    • 1970年2月26日
    • 联系 :capelin@qq.com 微信:imcapelin
    • 查看更多 >
    热门文章
    标签
    Delphi Android PHP Tools