Good afternoon, I am working on a C# application that needs to connect to HPQC v12.50 using the REST API. I have been able to authenticate and then I am trying to re-use the cookie I received as a webresponse to perform queries. However, I am stuck with an error 401 and after having read multiple forums and HP's doc about the REST API, I can't figure out what I am doing wrong.
Here is my chunk of code:
public void LoginAlm(string StrServer, string StrUser, string StrPassword, string StrDomain, string StrProject)
{
//First, I am authenticating to the server (this works fine)
string StrServerLogin = StrServer + "/authentication-point/authenticate";
HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(StrServerLogin);
myWebRequest.Headers[HttpRequestHeader.Authorization] = "Basic " + Base64Encode(StrUser + ":" + StrPassword);
WebResponse webResponse = myWebRequest.GetResponse();
//Then, I am extracting the cookie from the header to re-use it for me subsequent requests.
HttpWebRequest myWebRequest1 = (HttpWebRequest)WebRequest.Create(StrServer + "/rest/domains/"+StrDomain+"/projects/"+StrProject+"/defects");
string StrCookie = webResponse.Headers.ToString();
StrCookie = StrCookie.Substring(StrCookie.IndexOf("Set-Cookie:") + 12);
StrCookie = StrCookie.Substring(0, StrCookie.IndexOf("\r\n"));
myWebRequest1.Headers[HttpRequestHeader.Cookie] = StrCookie;
//Then, I am trying to perform my request, and the following line would always return an error 401.
WebResponse webResponse1 = myWebRequest1.GetResponse();
StreamReader reader = new StreamReader(webResponse1.GetResponseStream());
textBox6.Text = reader.ReadToEnd();
}
One thing I noticed in HP's doc is that I should be receiving a token as a response, but it does not seem to be there...
It is my first experience with REST API and I am sorry if it seems trivial but I've wasted too much time on this already!