这是我第一次使用RestSharp& amp; HP ALM Rest API。在代码中我似乎一切都好,但仍然会收到未经授权的错误。
任何线索,我错过了哪里?
(List(a),0)
(List(b, c),1)
(List(d),3)
(List(e, f),4)
我得到的错误是
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);
答案 0 :(得分: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);
}