[英]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.