【发布时间】:2011-03-08 12:45:22
【问题描述】:
我正在尝试使用 httpwebrequest 对象登录www.diary.com。但是,它总是无法登录,并不断给我返回登录页面。谁能告诉我什么是错的?
我的代码如下:
// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(@"http://diary.com/events/agenda");
request.ContentType = "text/html";
request.Credentials = new NetworkCredential(@"user@hotmail.com", "password");
request.AllowAutoRedirect = true;
request.Referer = @"http://diary.com/";
// execute the request
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();
// set the WebBrowser object documentStream to the response stream
myWB.DocumentStream = resStream;
// simply tell me the title of the webpage
MessageBox.Show(myWB.Document.Title);
【问题讨论】:
标签: c# httpwebrequest screen-scraping credentials