Basic验证的Domain处理

来源:互联网 发布:淘宝全屏海报怎么制作 编辑:程序博客网 时间:2024/05/21 15:39
 
Basic验证的Domain处理
 
Email:zfive5@yahoo.com.cn
Author:zfive5(zhaozi)
 
发觉自己对网络编程真是有些末名的潜力,过去编写basic代理认证时,往往乎略Domain,最近发现Domainbasic的编码中也有体现!
 
如果有域值的需要这样的:
 
"Proxy-Authorization:Basic"+" "+Base64(Domain+“/"+UserName+":"+Password)
 
"WWW-Authorization:Basic"+" "+Base64(Domain+“/"+UserName+":"+Password)
 
如果没有域值:
 
"Proxy-Authorization:Basic"+" "+Base64(UserName+":"+Password)
 
"WWW-Authorization:Basic"+" "+Base64(UserName+":"+Password)
 
 
.NET下的Reflector反编译的代码
 
NetworkCredential credential1 = credentials.GetCredential(httpWebRequest.ChallengedUri, BasicClient.Signature);
if (credential1 == null)
{
    return null;
}
 
string text1 = credential1.UserName;
string text2 = credential1.Domain;
if (ValidationHelper.IsBlankString(text1))
{
    return null;
}
 
string text3 = (!ValidationHelper.IsBlankString(text2) ? (text2 + @"/") : "") + text1 + ":" + credential1.Password;
byte[] buffer1 = BasicClient.EncodingRightGetBytes(text3);
string text4 = "Basic " + Convert.ToBase64String(buffer1);
return new Authorization(text4);
 
源码之下,确实可以解决一些疑问。