WebClient阈值401认证错误 [英] WebClient thriugh 401 authentication error

查看:122
本文介绍了WebClient阈值401认证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试从HTTPS URL下载网页源代码,我的代码如下:

Hi,

I''m trying to download the web page source code from a HTTPS URL, my code is as follows:

System.Net.WebClient WC = new System.Net.WebClient();

           NetworkCredential Cred = new NetworkCredential();
           Cred.UserName = "user";
           Cred.Password = "pass";

           WC.Credentials = Cred;

           System.IO.Stream s = WC.OpenRead("https://xxxxxx/data.html");
           System.IO.StreamReader sr = new System.IO.StreamReader(s);
           string webpage = sr.ReadToEnd();


我收到401(未经授权)异常,我100%确定凭据正确无误,并且可以在Web浏览器中完美地运行该文件.

我已经在标准HTTP URL上没有凭据的情况下测试了此代码,并且工作正常.

有什么想法我做错了吗?

感谢您的帮助


I get a 401 (unauthorized) exception, and i am 100% sure the credentials are correct, and work perfectly in my web browser for the file.

I have tested this code without the credentials, on a standard HTTP URL and it works fine.

Any ideas what I am doing wrong?

Thanks for any help

推荐答案

您可以在以下链接
中引用我的解决方案 VB.NET无法连接到HTTPS Web服务器 [
You can refer my solution mentioned at following link
VB.NET can''t connect to a HTTPS Web Server[^]


这篇关于WebClient阈值401认证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆