简体   繁体   English

如何使用TEmbeddedWB获取所有cookie详细信息?

[英]How to get all cookie details with TEmbeddedWB?

In a Delphi XE8 VCL Form Aplication, with TEmbeddedWB I get the cookies with this method: 德尔福XE8 VCL形式Aplication,与TEmbeddedWB我得到这个方法的饼干:

CookieStr := EmbeddedWB1.Cookie;
CodeSite.Send('CookieStr', CookieStr);

This is the result (for example): 这是结果(例如):

name1=value1; NAME1 =值1; name2=value2; 2 =值2; name3=value3 NAME3 =值3

However, as you can see, this gets only the name and value of the cookies. 但是,如您所见,这仅获取cookie的名称

So how can I get the other cookie fields such as path , expiration date , etc.? 那么,如何获取其他cookie字段,例如path到期日期等?

Here is the solution: 解决方法如下:

First, we need to make us familiar with the Winapi FILETIME structure . 首先,我们需要使我们熟悉Winapi FILETIME结构

Then get the IE cookie files from here: 然后从此处获取IE cookie文件:

C:\\Users\\%username%\\AppData\\Roaming\\Microsoft\\Windows\\Cookies\\ C:\\用户\\%USERNAME%\\ AppData的\\漫游\\微软\\的Windows \\饼干\\

Now look for the cookie files with the identical name=value pairs you got from TEmbeddedWB.Cookie . 现在,查找具有与TEmbeddedWB.Cookie相同的name=value对的cookie文件。

Here is an example of the content of a IE cookie file, where we take our data from: 这是IE Cookie文件内容的示例,我们从中获取数据:

在此处输入图片说明

(Similarities with people alive or other authorities are purely accidental and not intended!) (与活着的人或其他当局的相似之处纯属偶然,并非故意!)

We can see the meaning of the various numbers from the red colored comments. 我们可以从红色注释中看到各种数字的含义。

And here is the source code to decipher those numbers: 以下是解密这些数字的源代码:

uses Winapi.Windows;

function ConvertWinapiFileTimeLoHiValuesToDateTimeStr(const AFTLoValue, AFTHiValue: Cardinal): string;
const
  InvalidDate = '01/01/80 12:00:00 AM';
var
  lCookieFileTime: TFileTime;
  lDosDT: Integer;
  lLocalFileTime: TFileTime;
begin
  lCookieFileTime.dwLowDateTime  := AFTLoValue;
  lCookieFileTime.dwHighDateTime := AFTHiValue;

  FileTimeToLocalFiletime(lCookieFileTime, lLocalFileTime);
  if FileTimeToDosDateTime(lLocalFileTime, Longrec(lDosDT).Hi, Longrec(lDosDT).Lo) then
  begin
    try
      Result := DateTimeToStr(FiledateToDatetime(lDosDT));
    except
      Result := InvalidDate;
    end;
  end
  else
    Result := InvalidDate;
end;

Now we can use this function with the numbers from the above cookie file, as an example: 现在,我们可以将此函数与上面cookie文件中的数字一起使用,例如:

CodeSite.Send('Expiration Date', ConvertWinapiFileTimeLoHiValuesToDateTimeStr(2496134912, 30471078));
CodeSite.Send('Modified Date', ConvertWinapiFileTimeLoHiValuesToDateTimeStr(2624224682, 30465043));

Which will give us this result: 这将给我们以下结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM