2016-06-27 3 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); 
} 
관련 문제