Jira REST API返回错误请求

时间:2017-04-12 05:27:02

标签: c# asp.net-mvc jira-rest-api

我正在尝试使用以下代码在jira中创建一个问题。我运行了这段代码,之前它运行良好。但是现在,它返回了错误的请求,请帮助。 感谢。

class Program
    {
        static void Main(string[] args)
        {

            var data = new Issue();
            data.fields.project.key = "CAM";
            data.fields.summary = "test";
            data.fields.description = "test";
            data.fields.issuetype.name = "Task";

            string postUrl = "https://abcd.atlassian.net/rest/api/2/latest";

            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();

            client.BaseAddress = new System.Uri(postUrl);
            byte[] cred = UTF8Encoding.UTF8.GetBytes("username@gmail.com:password");
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.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<string>(data, jsonFormatter);
            System.Net.Http.HttpContent content = new System.Net.Http.ObjectContent<Issue>(data, jsonFormatter);
            System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;

            if (response.IsSuccessStatusCode)
            {
                string result = response.Content.ReadAsStringAsync().Result;
                Console.Write(result);
            }
            else
            {
                Console.Write(response.StatusCode.ToString());
                Console.ReadLine();
            }

        }
    }

1 个答案:

答案 0 :(得分:0)

使用以下链接: var/cache/test