【发布时间】:2014-10-01 03:27:55
【问题描述】:
我正在尝试从具有用户名和密码的网页中解析文本(或将文本下载为 .txt 文件)。几天来,我一直在网上和 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 的孩子?
-
提示windows登录