我尝试在授权后使用webBrowser1更改链接,但是webBrowser1打开了起始站点
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("http://server/application/login/");
pause_wb();
webBrowser1.Document.GetElementById("username").InnerText = "user1";
pause_wb();
webBrowser1.Document.GetElementById("password").SetAttribute("value", "pass1");
pause_wb();
webBrowser1.Document.GetElementById("userSignIn").InvokeMember("click");
pause_wb();
webBrowser1.Navigate("http://server/application/obj/");
}
暂停加载
public void pause_wb()
{
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
}
如果在字符串webBrowser1.Navigate(“ http://server/application/obj/”)之后运行程序, webBrowser1去启动站点http://server/application/login/
如何更改链接并保存授权?
答案 0 :(得分:0)
已解决
string g_cook = "";
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
private void button1_Click(object sender, EventArgs e)
{
g_cook = webBrowser1.Document.Cookie.ToString();
InternetSetCookie("http://server/application/", null, g_cook);
webBrowser1.Navigate("http://server/application/obj/");
}