2016-06-27 9 views
0

これはRestSharpの初めての試みです& HP ALM Rest API。すべてがコードで私には大丈夫だが、依然として応答の不正なエラーが発生しています。RestSharpはHP ALMに接続していません

手がかりはどこですか?私は取得しています

var client = new RestClient(); 
      client.BaseUrl = new Uri("http://abc:8080/qcbin/"); 
      client.Authenticator = new HttpBasicAuthenticator("poprawem", "abc`enter code here`"); 
      client.CookieContainer = new System.Net.CookieContainer(); 

      var request2 = new RestRequest("rest/domains/Projects/projects/Newgen/defects/"); 

      IRestResponse response = client.Execute(request2); 

エラーは、認証し、最初のセッションを作成する必要があります

<html> 
 
<head> 
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
 
<title>Error 401 Authentication failed. Browser based integrations - to login append '?login-form-required=y' to the url you tried to access.</title> 
 
</head> 
 
<body><h2>HTTP ERROR 401</h2> 
 
<p>Problem accessing /qcbin/rest/domains/Projects/projects/Newgen/defects/. Reason: 
 
<pre> Authentication failed. Browser based integrations - to login append '?login-form-required=y' to the url you tried to access.</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/> 
 

 
</body> 
 
</html>

答えて

0

です。

var almServerUri = new Uri("http://alm.server.com/qcbin/"); 

var client = new RestClient(); 
client.BaseUrl = almServerUri; 
client.Authenticator = new HttpBasicAuthenticator("poprawem", "abc`enter code here`"); 
client.CookieContainer = new System.Net.CookieContainer(); 

var authRequest = new RestRequest("authentication-point/authenticate"); 
var authResponse = client.Get(authRequest); 

var createSessionRequest = new RestRequest("rest/site-session"); 
var createSessionResponse = client.Post(createSessionRequest); 
try 
{ 
    //........... 
    //Do what you need here 
    //............ 
} 
finally 
{ 
    var closeSessionRequest = new RestRequest("rest/site-session"); 
    var closeSessionResponse = client.Delete(createSessionRequest); 
} 
関連する問題