-
忽然笑
获取 webrowser 的 Cookie ,可以通过 IHtmlDocument2 接口,访问 cookie 属性,以下是代码示例:1CooKies :=(WebBrowser1.Document as IHtmlDocument2).cookie;如果给其他组件使用,例如 IdHttp 组件,需要前面再添加“ Cookie:”做为标示符:123 CookieStr := 'Cookie: ' + CooKies; idHttp2.Request.CustomHeaders.Text := CookieStr; Memo1.Text := UTF8Decode(IDHttp1.Get(网址));
-
开心每一天1111
获取post,或者get返回的cookie,除了过滤返回的字符串之外,最简单的方法是使用idhttp的CookieManager属性。比如获得IDhttp返回的全部Cookie:if idhttp1.CookieManager.CookieCollection.Count > 0 thenfor i := 0 to idhttp1.CookieManager.CookieCollection.Count - 1 dotemp := temp + idhttp1.CookieManager.CookieCollection.Items[i] .CookieText + ';';也可以通过属性名和属性值的形式获得,这样就可以提取出个别的Cookie值:idhttp1.CookieManager.CookieCollection.Items[i].CookieName idhttp1.CookieManager.CookieCollection.Items[i].Value比如:temp := TStringList.Create;if idhttp1.CookieManager.CookieCollection.Count > 0 thenfor i := 0 to idhttp1.CookieManager.CookieCollection.Count - 1 do// temp := temp + idhttp1.CookieManager.CookieCollection.Items[i] .CookieText + ';';temp.Add(idhttp1.CookieManager.CookieCollection.Items[i].CookieName + '=' + idhttp1.CookieManager.CookieCollection.Items[i].Value);
-
MMTTMM
以下是使用步骤的演示代码:1、WebBrowswer 控件打开网址后,获取其 Cookie 值:1 CookieStr := 'Cookie: ' + (Web.document as IHtmlDocument2).cookie;2、将 Cookie 值传给 idhttp 控件使用:12 if CookieStr <> '' then IdHTTP1.Request.CustomHeaders.Text := CookieStr;