Skip to content

Instantly share code, notes, and snippets.

@jskeet
Last active April 4, 2018 18:38
Show Gist options
  • Save jskeet/24fc234cc1e9d6c5106714d1b106849f to your computer and use it in GitHub Desktop.
Save jskeet/24fc234cc1e9d6c5106714d1b106849f to your computer and use it in GitHub Desktop.
string type = "test";
string data = @"{""fields"":{""project"":{""key"": ""MD""},""summary"":
""Support EXAMPLE"",""description"": ""Testing Support"",""issuetype"":
{""name"": "+ type +" }}}";
string postUrl = "https://aconline.atlassian.net/rest/api/2/issue";
byte[] cred = UTF8Encoding.UTF8.GetBytes("username:password");
HttpClient client = new HttpClient
{
DefaultRequestHeaders =
{
Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred)),
Accept = { new MediaTypeWithQualityHeaderValue("application/json") }
},
BaseAddress = new Uri(postUrl)
};
HttpContent content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync("issue", content).Result;
if (response.IsSuccessStatusCode)
{
ViewData["Result"] = "Success! your issue has been posted.";
}
else
{
ViewData["Result"] = response.Content.ReadAsStringAsync().Result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment