如何获得来自Internet Explorer中的Cookie关联过期日期和标志? [英] How to get expiration date and flags associated with a cookie from Internet Explorer?

查看:228
本文介绍了如何获得来自Internet Explorer中的Cookie关联过期日期和标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以的 InternetGetCookie 或的 InternetGetCookieEx 。不过,我倒是希望得到到期日期和标志(仅Http,安全),以及数据。我找不到一个函数(C ++或C#),可以让我做到这一点从Internet Explorer(一个BHO)之内。


解决方案

 使用System.Net; 
使用系统;

HttpWebRequest的要求=(HttpWebRequest的)WebRequest.Create(小于您的网址>);
request.CookieContainer =新的CookieContainer();

HttpWebResponse响应=(HttpWebResponse)request.GetResponse();

//打印每个Cookie的属性。
的foreach(曲奇厨师在response.Cookies)
{
Console.WriteLine(曲奇);
Console.WriteLine({0} = {1},cook.Name,cook.Value);
Console.WriteLine(域名:{0},cook.Domain);
Console.WriteLine(路径:{0},cook.Path);
Console.WriteLine(端口:{0},cook.Port);
Console.WriteLine(安全:{0},cook.Secure);

Console.WriteLine(当发出:{0},cook.TimeStamp);
Console.WriteLine(过期:{0}(过期{1})?,cook.Expires,cook.Expired);
Console.WriteLine(不要保存:{0},cook.Discard);
Console.WriteLine(评论:{0},cook.Comment);
Console.WriteLine(URI征求意见:{0},cook.CommentUri);
Console.WriteLine(版本:RFC {0},cook.Version == 12109:2965);

//显示cookie的字符串表示。
Console.WriteLine(字符串:{0},cook.ToString());
}


I can get the value of a cookie with InternetGetCookie or InternetGetCookieEx. But I 'd like to get the expiration date and the flags (httpOnly, secure) as well as the data. I couldn't find a function (C++ or C#) that allows me to do that from within Internet Explorer (a BHO).

解决方案

using System.Net;
using System;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(<your URL>);
request.CookieContainer = new CookieContainer();

HttpWebResponse response = (HttpWebResponse) request.GetResponse();

// Print the properties of each cookie.
foreach (Cookie cook in response.Cookies)
{
  Console.WriteLine("Cookie:");
  Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
  Console.WriteLine("Domain: {0}", cook.Domain);
  Console.WriteLine("Path: {0}", cook.Path);
  Console.WriteLine("Port: {0}", cook.Port);
  Console.WriteLine("Secure: {0}", cook.Secure);

  Console.WriteLine("When issued: {0}", cook.TimeStamp);
  Console.WriteLine("Expires: {0} (expired? {1})", cook.Expires, cook.Expired);
  Console.WriteLine("Don't save: {0}", cook.Discard);    
  Console.WriteLine("Comment: {0}", cook.Comment);
  Console.WriteLine("Uri for comments: {0}", cook.CommentUri);
  Console.WriteLine("Version: RFC {0}" , cook.Version == 1 ? "2109" : "2965");

  // Show the string representation of the cookie.
  Console.WriteLine ("String: {0}", cook.ToString());
}

这篇关于如何获得来自Internet Explorer中的Cookie关联过期日期和标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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