WebClient生成(401)未授权的错误 [英] WebClient generates (401) Unauthorized error

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

问题描述

我在Windows服务中运行以下代码:

  WebClient webClient = new WebClient(); 
webClient.Credentials = new NetworkCredential(me,12345,evilcorp.com);
webClient.DownloadFile(downloadUrl,filePath);

每次我收到以下异常

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

具有以下内部异常:

  {不支持请求的功能} 

我知道凭据有效,实际上,如果我在我的网页浏览器中下载downloadrr并放入我的凭证为evilcorp.com \me,密码为12345,它下载得很好。



有什么奇怪的是,如果我用12345指定我的凭证为me@evilcorp.com ,它似乎失败了。



有没有办法格式化凭证?

解决方案>

显然,您正在运行的操作系统是重要的,因为默认加密在操作系统之间已更改。
这个博客有更多的细节: http:// ferozedaud.blogspot.com/2009/10/ntlm-auth-fails-with.html



这显然也在stackoverflow上讨论过: 407需要验证 - 不发送任何挑战



我建议先阅读博客,因为蒸馏的知识就在那里。


I have the following code running in a windows service:

WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential("me", "12345", "evilcorp.com");
webClient.DownloadFile(downloadUrl, filePath);

Each time, I get the following exception

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

With the following inner exception:

{"The function requested is not supported"}

I know for sure the credentials are valid, in fact, if I go to downloadUrl in my web browser and put in my credentials as evilcorp.com\me with password 12345, it downloads fine.

What is weird though is that if I specify my credentials as me@evilcorp.com with 12345, it appears to fail.

Is there a way to format credentials?

解决方案

Apparently the OS you are running on matters, as the default encryption has changed between OSes. This blog has more details: http://ferozedaud.blogspot.com/2009/10/ntlm-auth-fails-with.html

This has apparently also been discussed on stackoverflow here: 407 Authentication required - no challenge sent

I would suggest read the blog first as the distilled knowledge is there.

这篇关于WebClient生成(401)未授权的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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