在网上搜索了一下.说是可以用InternetGetCookie这个api来获得cookie
用以下代码
[System.Runtime.InteropServices.DllImport("wininet.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
public static extern bool InternetGetCookie(string lpszUrlName, string lpszCookieName, StringBuilder lpszCookieData, ref int lpdwSize);
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
internal static extern Int32 GetLastError(); public static string GetCookie(string url) //Win32 API
{
int size = 1000;
StringBuilder sb = new StringBuilder(size); if (!InternetGetCookie(url, "", sb, ref size))
{
Console.WriteLine("Error code:{0}", GetLastError());
}
return sb.ToString();
}
static void Main(string[] args)
{
System.Console.WriteLine(GetCookie("http://www.google.com/"));
}返回错误结果Error code:259网上写着说什么不支持xp sp2.不知道有没有什么解决方法?
用以下代码
[System.Runtime.InteropServices.DllImport("wininet.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
public static extern bool InternetGetCookie(string lpszUrlName, string lpszCookieName, StringBuilder lpszCookieData, ref int lpdwSize);
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
internal static extern Int32 GetLastError(); public static string GetCookie(string url) //Win32 API
{
int size = 1000;
StringBuilder sb = new StringBuilder(size); if (!InternetGetCookie(url, "", sb, ref size))
{
Console.WriteLine("Error code:{0}", GetLastError());
}
return sb.ToString();
}
static void Main(string[] args)
{
System.Console.WriteLine(GetCookie("http://www.google.com/"));
}返回错误结果Error code:259网上写着说什么不支持xp sp2.不知道有没有什么解决方法?
解决方案 »
- 在XP下搭建 windows phone 7的开发环境
- asp.net怎么实现SaveFileDialog
- 关于SQL
- IDbCommandBuilder ?
- 貌似VS2008的bug
- 截取字符串的问题,小妹暂时没有分,有分了补,谢谢各位!!!
- 两个List进行比较..修改值
- 如何把数据库中的数据取出生成XML文件。
- 如何在IE的右键菜单中添加一项,点击以后执行自己的程序。
- Datagrid?
- 我继承了DataGridTextBoxColumn类,和EventArgs类,实现了DataGrid行的颜色按照字段值的变化而变化.问题是如何把这两个类做可重复使用的类?
- C# 窗体继承 删除后新添己存在问题
不如用户名@google[1].txt这样类似的.
我试了好些站点都这样.