• delphi 获取webbrowser的cookies给Idhttp用


    网上方法一:(可获取,但不完全)

     引用mshtml;

       IHTMLDocument(wb1.Document).cooke; 


    网上方法二:(获取不到!)

    引用winnet,使用InternetGetCookieEx


    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;


    方法三:

    引用winnet,直接调用InternetGetCookie


    function GetWBCookies(URL: string): string;
    var
      data : array[0..10240] of Byte;
      datalen : cardinal;
    begin
      Result  := '';
      datalen := sizeof(data);
      if InternetGetCookie(PChar(URL), nil, @data,datalen) then
        Result := PChar(@data);
    end;

  • 相关阅读:
    SQL code for the partitoned example
    去掉重复的列名.txt
    末公开的存储过程.txt
    LauncherClass
    Retina时代的前端视觉优化
    获得数据库中表字段的名字.txt
    StaticConstructor.cs
    UNION ALL实现的分级汇总示例.sql
    SignAndSeal
    在现有数据库上还原时的数据文件处理示例.sql
  • 原文地址:https://www.cnblogs.com/xtfnpgy/p/9285374.html
Copyright © 2020-2023  润新知