I have created C# application to create issue in JIRA using REST API . I am sending the request with data in URI but instead of getting the response key of created issue , i am getting HTML response to create issue in JIRA .
i Am using following code .
data = @{ "fields"": {
""project"":
{ ""key"": ""TSI"" }
,
""summary"": ""Test Ticket"",
""description"": ""Creating an issue using project keys and issue type names using the REST API"",
""issuetype"":
{ ""name"": ""1"" }
,
""assignee"":
{ ""name"": ""sajwagner"" }
,""reporter"":
{ ""name"": ""sajwagner"" }
}
}";
string postUrl = "https://jira-int.lufthansa.com/rest/api/2/";
HttpClient client = new HttpClient();
client.BaseAddress = new System.Uri(postUrl);
byte[] cred = UTF8Encoding.UTF8.GetBytes(m_Username + ":" + m_Password);
//byte[] cred = UTF8Encoding.UTF8.GetBytes("sajwagner:Lh2013");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
System.Net.Http.Formatting.MediaTypeFormatter jsonFormatter = new System.Net.Http.Formatting.JsonMediaTypeFormatter();
//System.Net.Http.HttpContent content = new System.Net.Http.ObjectContent<Issue>(data, jsonFormatter);
var content = new StringContent(data, Encoding.UTF8, "application/json");
//HttpContent content = new ObjectContent<string>(data, jsonFormatter);
HttpResponseMessage response = client.PostAsync("/secure/CreateIssueDetails!init.jspa?pid=11080&issuetype=1&summary=Test Ticket&description=Creating an issue using project keys and issue type names using the REST API&reporter=sajwagner&assignee=sajwagner", content).Result;
if (response.IsSuccessStatusCode)
{ string result = response.Content.ReadAsStringAsync().Result; Console.WriteLine(result); }