[英]401(unauthorised) while making service call
进行Web API控制器调用时获得401(授权)
public bool CheckCarrierSCAC(int carrierID)
{
bool carrierScacSatus = false;
carrierSCAC = new BackOfficeViewController().GetSCACCodeBYCarrierID(carrierID);
logger.LogMessage(message: string.Format("Credentials {0}{1}", ConfigurationManager.AppSettings["HermesUserName"], ConfigurationManager.AppSettings["HermesPassword"]), logDate: true);
Http.Preauthenticate = true;
string serviceUrl = string.Format("{0}/CarrierSCAC?carrier={1}", ConfigurationManager.AppSettings["GatewayInterface"], carrierSCAC);
logger.LogMessage(message: string.Format("Check Carrier SCAC Service URL {0} ", serviceUrl), logDate: true);
try
{
carrierScacSatus = Http.Get<bool>(uri: serviceUrl, cookieContainer: null, contentType: "application/json");
}
catch (Exception exception)
{
logger.LogException(exception, message: "error while check Carrier Scac =" + exception.Message);
}
return carrierScacSatus;
}
我已经使用了预身份验证仍然收到相同的错误
设置Http.Preauthenticate = true
只是告诉Web请求将Authorization
标Http.Preauthenticate = true
送到该Uri,假设它是对.NET的HttpWebRequest.Preauthenticate
的传递。 在这种情况下,您似乎并没有实际向Web请求提供任何凭据。 您引用凭据的唯一情况是在记录器消息中。
Http.Get<T>
方法应该允许您提供原始的Header值(在这种情况下,您需要添加自己的Authorization
标头)或凭据,以便它为您创建标头。 (这似乎是一个包装C# WebRequest
或类似连接库的库,因此您需要查看其文档以了解具体细节)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.