webBrowser not navigating, even when DocumentStream is set?
I'm trying to load a page in WebBrowser thorugh responseStream sent by the server. I tried setting, its DocumentStream property but the browser is not navigating. This is my code:
private void btnFbConnect_Click(object sender, EventArgs e)
{
WebRequest request = W开发者_如何转开发ebRequest.Create("http://www.facebook.com");
request.Method = "GET";
WebResponse response = request.GetResponse();
StreamReader rdr = new StreamReader(response.GetResponseStream());
webBrowser1.DocumentStream = rdr.BaseStream;// after this line, I'm expecting the browser to display the facebook login page.
MessageBox.Show(rdr.ReadToEnd());
rdr.Close();
response.Close();
}
Am I missing an intermediate step or something??? If not, what might be causing the browser not to cause navigation???
Don't close the stream before the WebBrowser
accesses it.
WebRequest request = WebRequest.Create("http://www.facebook.com");
request.Method = "GET";
WebResponse response = request.GetResponse();
StreamReader rdr = new StreamReader(response.GetResponseStream());
webBrowser1.DocumentStream = rdr.BaseStream;// after this line, I'm expecting the browser to display the facebook login page.
MessageBox.Show(rdr.ReadToEnd());
//rdr.Close();
//response.Close();
Additionally, you might encounter a error because the relative path resources on the server cannot be resolved. So, I recommend you use:
webBrowser1.Navigate("http://www.facebook.com");
精彩评论