本文介绍了在HTTP请求头缺少基本的HTTP认证入口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code:
WebClient client = new WebClient();
String un = "Username";
String pw = "Password";
client.Credentials = new System.Net.NetworkCredential(un,pw);
client.DownloadFileCompleted +=
new AsyncCompletedEventHandler(downloadFileCompleted);
client.DownloadFileAsync(new Uri(url), Config.LocalDir + @"\data\supportData.xml");
我收到以下的服务器上使用NetworkMonitor:
Using NetworkMonitor on the server I receive the following:
Http: Request, GET /audiClave/REST/en/actions
Command: GET
URI: /audiClave/REST/en/actions
ProtocolVersion: HTTP/1.1
Host: 210.xxx.xxx.xxx:8080
Connection: Keep-Alive
HeaderEnd: CRLF
没有认证的条目。我缺少什么?
No Authentication entry. What am I missing?
推荐答案
尝试的老式方法:
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(un + ":" + pw));
client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
IIRC的WebClient没有,直到它得到来自服务器的挑战与401发送的授权请求报头。
IIRC WebClient doesn't send the Authorization request header until it gets a challenge from the server with 401.
这篇关于在HTTP请求头缺少基本的HTTP认证入口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!