我无法登录网页 (http://hurt.prosto.pl);它一直返回到登录页面源...知道如何解决吗?
var loginData = new NameValueCollection();
loginData.Add("username", username);
loginData.Add("password", password);
var client = new CookieAwareWebClient();
client.BaseAddress = @"http://hurt.prosto.pl/accounts/login/?next=/hurt/";
client.UploadValues("http://hurt.prosto.pl/accounts/login/?next=/hurt/", "POST", loginData);
// now you are logged in and can request pages
string htmlSource = client.DownloadString("http://hurt.prosto.pl/hurt/myorders/--/category/all1/");
webBrowser2.DocumentText = htmlSource;
这是我的 CookieAwereWebClient 类:
namespace HTMLParser
{
internal class CookieAwareWebClient : WebClient
{
private CookieContainer cookie = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = cookie;
}
return request;
}
}
}