winForm写cookie经过

1.引进
名称空间 using System.Runtime.InteropServices;
2.注册
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
3.
#region 写入cookie
// set cookie
InternetSetCookie(url, "Token", "value=" + strToken +"; expires=Thu, 01-Jan-2020 00:00:01 GMT");
// navigate
webBrowser1.Navigate(url);
#endregion
注意      : InternetSetCookie (url地址,cookie名称,cookie内容及过期时间) 
expires过期时间格式应该为GMT

你可能感兴趣的:(WinForm)