[英]401(unauthorised) while making service call
Getting 401(authorised) while making web api controller 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;
}
I have already used preauthentication still getting same error 我已经使用了预身份验证仍然收到相同的错误
Setting Http.Preauthenticate = true
just tells the web request to send the Authorization
header to that Uri going forward, assuming it's a pass-through to .NET's HttpWebRequest.Preauthenticate
. 设置
Http.Preauthenticate = true
只是告诉Web请求将Authorization
标Http.Preauthenticate = true
送到该Uri,假设它是对.NET的HttpWebRequest.Preauthenticate
的传递。 In this case, you don't appear to actually be providing any credentials to the web request. 在这种情况下,您似乎并没有实际向Web请求提供任何凭据。 The only case where you reference the credentials is in the logger message.
您引用凭据的唯一情况是在记录器消息中。
The Http.Get<T>
method should allow you to provide either raw Header values (in which case you'll need to add your own Authorization
header) or the credentials so that it creates the header for you. Http.Get<T>
方法应该允许您提供原始的Header值(在这种情况下,您需要添加自己的Authorization
标头)或凭据,以便它为您创建标头。 (This appears to be a library that wraps the C# WebRequest
or some similar connection library, so you'll need to check it's documentation for specific details). (这似乎是一个包装C#
WebRequest
或类似连接库的库,因此您需要查看其文档以了解具体细节)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.