我在C#中使用WebBrowser
來顯示包含登錄表單的網站。在我成功登錄後,網站的某些部分未在WebBrowser
中顯示,但在默認瀏覽器中顯示的是同一網站。WinForms WebBrowser控件不加載整個網站
另一個問題是,當我點擊WebBrowser
中的鏈接時,它會在默認瀏覽器(Firefox,chrome等)中打開。
我的應用程序自動設置用戶名和密碼登錄。
ChangeUserAgent();
var request = (HttpWebRequest)WebRequest.Create(loadLinks(namewebsite));
string useragent = request.UserAgent = "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393";
webBrowser2.Navigate(request.RequestUri,null,null, "User-Agent:Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393");
loadauthintication(namewebsite, _username, _password);
它是方法loadauthintication
using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString(@"http://example.com/getauthintication.php?name="+name+"&user="+user+"&pass="+pass);
// Now parse with JSON.Net
// MessageBox.Show(json);
string[] array = json.Split('~');
username = array[0];
password = array[1];
}
方法
public void ChangeUserAgent()
{
ua = "Googlebot/2.1 (+http://www.google.com/bot.html)";
UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, null, 0, 0);
UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, ua, ua.Length, 0);
}
什麼是Windows論壇瀏覽器? –
webBrowser組件在C# –
顯示一些更多的代碼,它現在的樣子以及它應該是什麼樣子的截圖等等。 –