我试图从具有用户名和密码的网页解析文本(或将文本下载为.txt文件)。我一直在围绕net和stackoverflow巡回几天寻找解决方案。似乎应该有一个简单的解决方案,但迄今为止我无法找到它。下面的代码似乎是迄今为止我发现的最合理和最直接的代码。它目前正在返回一个错误401代码。验证密码保护的网站
private void Form1_Load(object sender, EventArgs e){
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback
(
delegate { return true; }
);
using (var client = new CookieAwareWebClient())
{
var values = new NameValueCollection
{
{ "username", "username" },
{ "password", "password" },
};
client.UploadValues("https://website/", values);
string result = client.DownloadString("https://website/licences");
lbl1.Text = result;
}
}
也许你正在尝试验证的网站正在使用某个孩子验证请求来自哪里,而不接受来自其他地方的POST? – Floremin 2014-09-30 19:13:12
它提示Windows登录 – 2014-10-01 18:32:22