远程服务器返回错误:(401)未经授权
我正在尝试获取某些网页的html代码, 我的用户名和密码是正确的,但我仍然无法让它工作, 这是我的代码:
private void buttondownloadfile_Click(object sender, EventArgs e)
{
NetworkCredentials nc = new NetworkCredentials("?", "?", "http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
WebClient client = new WebClient();
client.Credentials = nc;
String htmlCode = client.DownloadString("http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
MessageBox.Show(htmlCode);
}
MessageBox 只是为了测试它, 问题是每次我到达这一行:
String htmlCode = client.DownloadString("http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
我都会遇到异常:
远程服务器返回错误: (401) 未经授权。
我该如何解决这个问题?
I'm trying to get the html code of certain webpage,
I have a username and a password that are correct but i still can't get it to work,
this is my code:
private void buttondownloadfile_Click(object sender, EventArgs e)
{
NetworkCredentials nc = new NetworkCredentials("?", "?", "http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
WebClient client = new WebClient();
client.Credentials = nc;
String htmlCode = client.DownloadString("http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
MessageBox.Show(htmlCode);
}
The MessageBox is just to test it,
the problem is that every time I get to this line:
String htmlCode = client.DownloadString("http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
I get an exception:
The remote server returned an error:
(401) Unauthorized.
How do I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就我而言,
client.UseDefaultCredentials = true;
成功了。In my case
client.UseDefaultCredentials = true;
did the trick.我已经尝试过以下代码并且它有效。
I have tried the following code and it is working.
尝试创建一个没有该域部分的
NetworkCredential
:Try to create a
NetworkCredential
without that domain part: