从TWebBrowser获取Cookie [英] Getting Cookie from TWebBrowser

查看:155
本文介绍了从TWebBrowser获取Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用indy下载文件,(通过asp保存excel响应),但遇到错误,使用wireshark请求丢失了cookie。

Trying to download a file using indy,(post to asp save the excel response) but running into errors, using wireshark the request is missing cookies.

尝试

procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
var
document: IHTMLDocument2;
cookies:tstringlist;
begin
cookies:=tstringlist.Create;
document := WebBrowser1.Document as IHTMLDocument2;
cookies.Add(document.cookie);
//do stuff with them
end;

什么都不返回,从twebbrowser中提取cookie(或2)的最佳方法是什么?

returns nothing, whats the best way to extract a cookie(or 2) out of twebbrowser, or is there something better i'm missing?

推荐答案

TWebBrowser 是包装器吗? Internet Explorer,它本身就是WinInet的包装。 Indy不与IE / WinInet共享cookie,因此您必须手动将cookie详细信息复制到Indy的 TIdCookieManager 组件中。但是, IHTMLDocument2.cookie 属性只是 name = value 对的分隔字符串(如果它返回任何内容) ,由于安全性限制),其中包含的信息不足以供Indy使用,例如cookie的源URL和目标域/路径,因此您必须从其他地方获取该信息,例如通过解析IE存储的cookie文件在Windows的 Cookies 文件夹中。

TWebBrowser is a wrapper around Internet Explorer, which itself is a wrapper around WinInet. Indy does not share cookies with IE/WinInet, so you have to copy the cookie details manually into Indy's TIdCookieManager component. However, the IHTMLDocument2.cookie property is just a delimited string of name=value pairs (if it returns anything at all, due to security restrictions), which does not contain enough information for Indy's use, such as a cookie's source URL and target domain/path, so you have to get that information from somewhere else, such as by parsing IE's cookie files that are stored in Windows' Cookies folder.

这篇关于从TWebBrowser获取Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆