0
我正在使用RestSharp nuget包向端點發出http請求。在我的情況下,端點是tableau服務器。請求是用於可信身份驗證並獲取身份驗證票據作爲響應。RestSharp代碼不起作用,但在Postman休息客戶端中工作相同
使用Restsharp庫C#代碼
[HttpPost]
public ActionResult Logon(string url,string username)
{
string response = string.Empty;
try
{
RestClient client = new RestClient(url);
RestRequest logonRequest = new RestRequest("trusted");
logonRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
logonRequest.AddHeader("charset", "utf-8");
logonRequest.AddParameter("username", username,ParameterType.GetOrPost);
IRestResponse restResponse = client.ExecuteAsPost(logonRequest,"POST");
if (restResponse.StatusCode == System.Net.HttpStatusCode.OK)
{
response = restResponse.Content;
}
else
{
response = restResponse.ErrorMessage;
}
}
catch (Exception ex)
{
response = ex.Message;
}
return Json(response);
}
用戶名:用戶名誰不存在
基本上我期待的-1
的響應,因爲該用戶不存在於畫面上。郵差休息客戶端上的相同郵件請求完美無瑕。但restsharp報告unable to connect to server
。有什麼想法嗎 ?
參考: https://onlinehelp.tableau.com/current/server/en-us/trusted_auth_webrequ.htm
這一個作品了。 https://community.tableau.com/thread/130481