The Problem
I am trying to create a REST API call using a HttpWebRequest to our in-house Jira server. But somehow I keep getting back a (400) Bad Request error. I have also tried with WebClient and other ways but I just don't seem to find the correct approach. Any suggestions?
URL is correct
User is correct
Password is correct
JSON Data also correct
There must be another way of accessing the remote server right? I have been searching but not seem to find a solution.
My Code
public static void CreateJiraRequest(JiraApiObject.RootObject jiraApiObject)
{
string url = "https://jira-test.ch.*********.net/rest/api/latest/issue/";
string user = "peno.ch";
string password = "**********";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.Credentials = new System.Net.NetworkCredential(user, password);
string data = JsonConvert.SerializeObject(jiraApiObject);
using (var webStream = request.GetRequestStream())
using (var requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII))
{
requestWriter.Write(data);
}
try
{
var webResponse = request.GetResponse();
using (var responseReader = new StreamReader(webResponse.GetResponseStream()))
{
string response = responseReader.ReadToEnd();
}
}
catch (Exception ex)
{
throw ex;
}
}
JSON
{
"fields": {
"project":
{
"key": "FOO"
},
"summary": "Test the REST API",
"issuetype": {
"name": "Task"
}
}
}
Exception
The exception occurs when entering the try block on request.GetResponse();
Additional information: The remote server returned an error: (400) Bad Request.
Visit the Jira Wiki here