在winform里面經(jīng)常會用到WebBrowser,,這是一個難點(diǎn)就是如何設(shè)置cookies,注意,,Docment對象是只讀的,,所以WebBrowser.Docment.cookie也就只有get方法,沒有set方法,,下面將介紹如何設(shè)置cookies,。
public partial class WebBrowserControl : Form
{
private String url;
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
public WebBrowserControl(String path)
{
this.url = path;
InitializeComponent();
// set cookie
InternetSetCookie(url, "JSESSIONID", Globals.ThisDocument.sessionID);
// navigate
webBrowser.Navigate(url);
}
...
}
|