将webbrowser的cookie给idhttp用
网上搜索出来的方法是:Cookie:=
'Cookie:'
+(Web
.
document
as
IHtmlDocument2).cookie;
但听说这个方法不能获取全部的Cookie内容,需要借助wininet.dll才可以获取完整。
function GetCookie(url: string): string;
constINTERNET_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;
本文已关闭评论