小编Bec*_*coZ的帖子

c#httpwebrequest凭证问题

我正在尝试使用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);
Run Code Online (Sandbox Code Playgroud)

c# screen-scraping credentials httpwebrequest

1
推荐指数
1
解决办法
1273
查看次数

标签 统计

c# ×1

credentials ×1

httpwebrequest ×1

screen-scraping ×1