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

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

问题描述

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

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

我确信凭据有效,事实上,如果我在 Web 浏览器中访问 downloadUrl 并将凭据输入为 evilcorp.comme,密码为 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.comme with password 12345, it downloads fine.

奇怪的是,如果我将凭据指定为 me@evilcorp.com 和 12345,它似乎会失败.

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?

推荐答案

显然,您运行的操作系统很重要,因为操作系统之间的默认加密已更改.此博客有更多详细信息: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

这显然也在 stackoverflow 上讨论过:需要 407 身份验证- 没有发送挑战

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天全站免登陆