Call API HTTP header Authorization: Basic
2021-01-27 12:14
标签:bytes user ted ret settings ase account nbsp false Client eil_userid = BaseCmConfig.GetCustomSettings("EILUserId"); EILWS.GetAccountInfoBinding eil = new EILWS.GetAccountInfoBinding(); Server protected override System.Net.WebRequest GetWebRequest(Uri uri) Call API HTTP header Authorization: Basic 标签:bytes user ted ret settings ase account nbsp false 原文地址:https://www.cnblogs.com/ganting/p/11936890.html
eil_pw = BaseCmConfig.GetCustomSettings("EILPassword");
eil_pw = FMSEncrypt.Decrypt(eil_pw);
eil_nc = new NetworkCredential(eil_userid, eil_pw);
eil_url = "https://" + System.Configuration.ConfigurationManager.AppSettings["EILWS"].ToString();
eil_credentials = eil_nc.GetCredential(new Uri(eil_url), "Basic");
eil.Credentials = eil_credentials;
eil.PreAuthenticate = true;
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);
(request as System.Net.HttpWebRequest).KeepAlive = false;
if (PreAuthenticate)
{
NetworkCredential networkCredentials = Credentials.GetCredential(uri, "Basic");
if (networkCredentials != null)
{
byte[] credentialBuffer = new UTF8Encoding().GetBytes(networkCredentials.UserName + ":" + networkCredentials.Password);
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(credentialBuffer);
}
else
{
throw new ApplicationException("No network credentials");
}
}
return request;
}
文章标题:Call API HTTP header Authorization: Basic
文章链接:http://soscw.com/index.php/essay/47749.html