Web客户端生成(401)未经授权错误 [英] WebClient generates (401) Unauthorized error

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

问题描述

我有一个窗口服务下列code运行:

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."}

使用以下内部异常:

{"The function requested is not supported"}

我知道肯定凭证是有效的,事实上,如果我去downloadUrl在我的网页浏览器,并把我的凭据evilcorp.com \\我的密码12345,它下载的罚款。

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.

什么是奇怪的是,虽然如果我12345指定我的凭据me@evilcorp.com,似乎要失败的。

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?

推荐答案

显然你正在运行的问题,因为默认的加密已经操作系统之间变化的操作系统。
此博客有更多的细节:<一href=\"http://ferozedaud.blogspot.com/2009/10/ntlm-auth-fails-with.html\">http://ferozedaud.blogspot.com/2009/10/ntlm-auth-fails-with.html

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

这显然也已经对计算器这里讨论:<一href=\"http://stackoverflow.com/questions/1443617/407-authentication-required-no-challenge-sent/1482442#1482442\">http://stackoverflow.com/questions/1443617/407-authentication-required-no-challenge-sent/1482442#1482442

This has apparently also been discussed on stackoverflow here: http://stackoverflow.com/questions/1443617/407-authentication-required-no-challenge-sent/1482442#1482442

我建议阅读博客首先作为知识精华是存在的。

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

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

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