客户端程序如何提取访问网站的Cookie设置,例如我们要访问一个网站,如何提取网站设置到客户端的Cookie?
---------------------------------------------------------------
on the client side, use document.cookie, see GetCookie() function in the sample code on this URL:
---------------------------------------------------------------
what I said is applicable to the webform, if you are programming winform, you have to read the cookie file yourself, or use some win32 API, see how people try to delete the cookies:
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20493107.html
---------------------------------------------------------------
try
using System;
using System.Text;
using System.Runtime.InteropServices;
class TestCookie
{
[DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool InternetGetCookie(
string lpszUrlName,
string lpszCookieName,
StringBuilder lpszCookieData,
ref uint lpdwSize
);
[DllImport("kernel32.dll")]
internal static extern Int32 GetLastError();
public static string GetCookie(string url)
{
StringBuilder sb = new StringBuilder(1000);
uint size = 1000;
bool bGood = InternetGetCookie(url,"", sb,ref size);
if (!bGood)
Console.WriteLine("Error code:{0}", GetLastError());
return sb.ToString();
}
public static void Main()
{
Console.WriteLine(GetCookie("http://expert.csdn.net"));
}
}