错误:远程服务器返回错误:(401)未经授权。 [英] error:The remote server returned an error: (401) Unauthorized.

查看:512
本文介绍了错误:远程服务器返回错误:(401)未经授权。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





伙计们我在vb中以窗口形式创建了一个下载管理器。



下载我有以下代码:

Hi,

Guys i am creating a download manager in window form in vb.

For downloading i am having following code:

Dim webclient As New Net.WebClient()

       Dim URL As String
       Dim filename As String
       Dim filereader As StreamReader
       Dim line As String
       filereader = New StreamReader(OpenFileDialog1.FileName)
       TextBox1.Text = filereader.ReadLine()
       For i As Integer = 0 To nooflines
           URL = filereader.ReadLine()
           MsgBox(URL)
           filename = "F:\downloaded file" & i
           line = filereader.ReadLine()
           Do While filereader.Peek() >= 0
               nooflines = nooflines + 1
               line = filereader.ReadLine()
           Loop
           webclient.DownloadFile(URL, filename)


       Next



但是在(webclient.DownloadFile(URL,filename))这一行我有一个错误,上面写着 -



远程服务器返回错误:(401)未经授权。



它正在另一台电脑上工作,但在我的笔记本电脑中我遇到了这个错误。


But in (webclient.DownloadFile(URL, filename)) this line i am having an error which says -

"The remote server returned an error: (401) Unauthorized."

It is working on another pc but in my laptop I am facing this error.

推荐答案

你好,Shashank ,



通常错误消息401表示您需要先登录(先输入有效的用户ID和密码)。如果您刚刚输入这些,然后立即看到401错误,则表示您的一个或两个用户ID和密码因任何原因无效(输入错误,用户ID暂停等)。



你真正需要做的是向WebClient提供如下所示的凭据。

Hello, Shashank,

Generally error message 401 means you need to log on (enter a valid user ID and password) somewhere first. If you have just entered these and then immediately see a 401 error, it means that one or both of your user ID and password were invalid for whatever reason (entered incorrectly, user ID suspended etc.).

What you really need to do is to supply Credentials to the WebClient something like shown below.
WebClient client = new WebClient();
client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential("username", "password");



如果您的应用程序在身份验证代理后运行,那么您可能希望为代理服务器提供凭据,如下所示


If your app is running behind a authenticating proxy then you may want to supply the proxy server with credentials as shown below

WebClient client = new WebClient();
WebProxy wp = new WebProxy("PROXY_ID_OR_HOSTNAME", PROXY_PORT);
wp.Credentials = new NetworkCredential("NETWORK USER ID", "PASSWORD", "DOMAIN");
client.Proxy = wp;
client.DownloadFile("http://www.monsoondata.org/wx/changfs.png", "F:\\changfs.png");



问候,


Regards,


这篇关于错误:远程服务器返回错误:(401)未经授权。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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