2017-08-11 13 views
0

RestSharpのnugetパッケージを使用して、エンドポイントにhttpリクエストを送信しています。ここで私の場合、エンドポイントはtableauサーバーです。要求は信頼できる認証であり、応答として認証チケットを取得します。RestSharpコードは機能しませんが、Postman Restクライアントでも同じです

Restsharpライブラリ

[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); 
     } 

URL使用

C#コード:https://servername/trusted

ユーザ名:そのユーザにはないので、基本的に、私は-1の応答を期待してい

存在していないユーザーのユーザー名をタブローに存在する。クロムの郵便配達人のレストクライアントに対する同じ投稿要求が完璧に機能します。しかし、restharpはunable to connect to serverを報告しています。何かご意見は ?

参考: https://onlinehelp.tableau.com/current/server/en-us/trusted_auth_webrequ.htm

この1つはあまりにも動作します。 https://community.tableau.com/thread/130481

答えて

0

IEブラウザで設定されたシステムプロキシがC#コードで選択されていないようです。だから、私はweb.configでプロキシを指定しなければならず、うまくいきました。

<system.net> 
    <defaultProxy> 
     <proxy proxyaddress="http://server:port"/> 
    </defaultProxy> 
</system.net> 
関連する問題