c# – 如何通过REST api向JIRA创建问题?
发布时间:2020-12-15 22:09:32 所属栏目:百科 来源:网络整理
导读:我正在使用我的json数据向JIRA发送POST请求以创建项目,但是我无法在JIRA中创建项目,我试图从Fiddler看到错误并且我得到了以下错误.我正在使用C#并为它创建了控制台应用程序. 我发布的我的JSON数据如下. { "fields": { "project": { "key": "JTL" },"issuetyp
我正在使用我的json数据向JIRA发送POST请求以创建项目,但是我无法在JIRA中创建项目,我试图从Fiddler看到错误并且我得到了以下错误.我正在使用C#并为它创建了控制台应用程序.
我发布的我的JSON数据如下. { "fields": { "project": { "key": "JTL" },"issuetype": { "name": "BUG" } } } 错误消息如下:
我从以下代码发布json数据,请提出我错在哪里和哪里? string data=@"{"fields":{"project":{"key":"JTL"},"issuetype":{"name":"BUG"}}}"; //object of HttpClient. HttpClient client = new HttpClient(); //Putting URI in client base address. client.BaseAddress = new Uri(uri); //Putting the credentials as bytes. byte[] cred = UTF8Encoding.UTF8.GetBytes("jiraUserName" + ":" + "JiraPassword"); //Putting credentials in Authorization headers. client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic",Convert.ToBase64String(cred)); //Putting content-type into the Header. client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); //I am using StringContent because I am creating console application,no any serialize I used for manipulate the string. var content = new StringContent(data,Encoding.UTF8,"application/json"); //Sending the Post Request to the server. But getting 400 bad Request. System.Net.Http.HttpResponseMessage response = client.PostAsync("issue",content).Result; 在上面的代码中,您可以看到我正在发送授权用户和发送数据的凭据. 解决方法
更改您的数据如下:
string data = @"{'fields':{'project':{'key':'JTL'},'summary':'Sample issue','description':'Creating an issue via REST API','issuetype':{'name':'Bug'}}}"; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |