I'm trying to convert a curl request example from an API for Jira into a C# request.
This is the original Curl Request example that JIRA provides:
curl \
-D- \
-u charlie:charlie \
-X GET \
-H "Content-Type: application/json" \
http://localhost:8080/rest/api/2/search?jql=assignee=charlie
Which I've translated into the below code for JIRA:
However the response lines don't work - because I've cobbled together a few examples and got a bit stuck!
var myTask = curlRequestAsync(); // call your method which will return control once it hits await
string result = myTask.Result();
// .Result isn't defined - but I'm not sure how to access the response from my request!
Any help would be appreciated as I'm really stuck!
Full example:
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var myTask = curlRequestAsync(); // call your method which will return control once it hits await
string result = myTask.Result();
// wait for the task to complete to continue
}
protected async System.Threading.Tasks.Task curlRequestAsync()
{
try
{
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "http://myurl.co.uk/rest/api/2/search?jql=assignee=bob"))
{
var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("username:password"));
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");
var result = await httpClient.SendAsync(request);
return result;
}
}
}
catch (Exception ex)
{
error.InnerText = ex.Message;
}
}
}