I had this code below to download attachments from HP QC through API with C#. I think that I succeeded to log in to HP QC through API but I had the following two issues:
First, how should I do to ensure that I had connected successfully actually I am doing that by throwing a message box message that would be great if you had an additional method for that.
Second, I didn't figure out a way to download the attachments from HP ALM reqs after being logged in (I think I am). I've seen in a lot of posts over the web but usually, I see examples of that using Otaclient.dll, unfortunately, I could not use that since I am not able to register mine due to lack of admin privileges. Is there any way for that?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Reflection;
using System.Net.Http;
using System.Net.Http.Headers;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class Class3
{
public static void SetBasicAuthHeader(WebRequest request, String userName, String userPassword)
{
string authInfo = userName + ":" + userPassword;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers["Authorization"] = "Basic " + authInfo;
}
static void Main(string[] args)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
String ALMBASEURL = "ALM Server URL that ends with qcbin";
WebRequest request = WebRequest.Create(ALMBASEURL + "/api/authentication/sign-in");
SetBasicAuthHeader(request, "userName", "userPassword");
WebResponse response = request.GetResponse();
HttpWebResponse ORES = (HttpWebResponse)response;
if (ORES.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show("Login is successful" );
//I am here but @stackoverflow I need your help to bulk download HP ALM reqs attachements.
}
else
{
MessageBox.Show("Login NOT successful");
}
}
}
}