首页 > 代码库 > C# 调用动态链接库,给游览器写入Cookie
C# 调用动态链接库,给游览器写入Cookie
给游览器写入Cookie
class Program {
/// <summary>
/// 写
/// </summary>
/// <param name="lpszUrlName"></param>
/// <param name="lbszCookieName"></param>
/// <param name="lpszCookieData"></param>
/// <returns></returns>
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie ( string lpszUrlName, string lbszCookieName, string lpszCookieData );
/// <summary>
/// 读
/// </summary>
/// <param name="lpszUrlName"></param>
/// <param name="lbszCookieName"></param>
/// <param name="lpszCookieData"></param>
/// <param name="lpdwSize"></param>
/// <returns></returns>
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetGetCookie ( string lpszUrlName, string lbszCookieName, StringBuilder lpszCookieData, ref int lpdwSize );
/// <summary>
/// 异常
/// </summary>
/// <returns></returns>
[DllImport("kernel32.dll")]
public static extern Int32 GetLastError ();
static void Main ( string[] args ) {
System.Diagnostics.Process.Start("IEXPLORE.EXE", "http://172.16.5.63:8088/ws?uname=122");
System.Threading.Thread.Sleep(1000 * 10);
//System.Diagnostics.Process.Start("http://172.16.5.63:8088/ws?uname=122");
if ( !InternetSetCookie("http://172.16.5.63:8088", "Test", DateTime.Now + ";expires=Sun,22-Feb-2099 00:00:00 GMT") )
{
Console.WriteLine("错误消息:", GetLastError().ToString());
}
StringBuilder cookie = new StringBuilder(new String(‘ ‘, 2048));
int datasize = cookie.Length;
if ( !InternetGetCookie("http://172.16.5.63:8088", "Test", cookie, ref datasize) )
{
Console.WriteLine(GetLastError().ToString());
}
Console.WriteLine(cookie.ToString(), datasize);
Console.ReadLine();
}
}
C# 调用动态链接库,给游览器写入Cookie
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。