0

DownloadComplete WebBrwoser の InternetGetCookieEx から Cookie を取得します。hotmail にログインしようとすると、通過しますが、リダイレクトされます。Gmailは機能しますが。Web 解析のために WebBrowser から IdCookieManager に認証を転送するための普遍的なソリューションを見つけようとしています。

テスト プロジェクト = http://www.megafileupload.com/en/file/373536/Cookie-Tester-rar.html

IdHTTP では Cookie とリダイレクトが有効になっています。

Cookie を許可する必要があります お使いのブラウザは現在、Cookie をブロックするように設定されています。Windows Live ID を使用するには、ブラウザーで Cookie を許可する必要があります。

    function GetCookie(host: string): string;
    const
      INTERNET_COOKIE_HTTPONLY = 8192;
    var
      hModule: THandle;
      lp: Pointer;
      InternetGetCookieEx: function(lpszUrl, lpszCookieName, lpszCookieData
        : PAnsiChar; var lpdwSize: DWORD; dwFlags: DWORD; lpReserved: pointer)
        : BOOL; stdCall;
      CookieSize: DWORD;
      CookieData: PAnsiChar;
    begin
      LoadLibrary('wininet.dll');
      hModule := GetModuleHandle('wininet.dll');
      if hModule <> 0 then
      begin
        @InternetGetCookieEx := GetProcAddress(hModule, 'InternetGetCookieExA');
        if @InternetGetCookieEx <> nil then
        begin
          CookieSize := 1024;
          Cookiedata := AllocMem(CookieSize);
          if InternetGetCookieEx(PAnsiChar(AnsiString(host)), nil, Cookiedata, CookieSize, INTERNET_COOKIE_HTTPONLY, nil) then
          result:=cookiedata;
          FreeMem(Cookiedata);
        end;
      end;
    end;

procedure EmbeddedWB1DocumentComplete(ASender: TObject; const pDisp: IDispatch;
  var URL: OleVariant);
var
  document: IHTMLDocument2;
  cookies: TStringList;
  uri: TIdURI;
begin
  document := EmbeddedWB1.Document as IHTMLDocument2;
  cookies := TStringList.Create;
  try 
    cookies.Delimiter:=';';
    //cookies.DelimitedText:=GetCookie(document.url);
    cookies.DelimitedText:=document.cookie;
    uri := TIdURI.Create(document.url);
    try
      IdCookieManager1.AddServerCookies(cookies,uri);
      EmbeddedWB1.LoadFromString(http.Get(document.url));
    finally
      uri.Free;
    end;
  finally
    cookies.Free;
  end;
4

1 に答える 1

1

As I mentioned in your other question, you need to pre-parse the cookies you are extracting from the web browser. It is not enough to simply split the cookie string as-is on ; characters, since that delimiter is used to both delimit individual cookies from each other as well as delimit name=value data from parameter data within a single cookie. If you just split the entire string without taking that into account, your TStringList is not going to end up with correct cookie data, so you end up passing bad data to TIdCookieManager.

You might also consider using the NavigateComplete/2 events, as the DocumentComplete event might be too late when redirects are involved.

于 2012-11-07T19:54:45.613 に答える