Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JIRA rest API创建问题返回错误方法不允许_Api_Post_Jira - Fatal编程技术网

使用JIRA rest API创建问题返回错误方法不允许

使用JIRA rest API创建问题返回错误方法不允许,api,post,jira,Api,Post,Jira,我试图通过以下代码使用JiraRESTAPI创建问题 string data = @"{ ""fields"": { ""project"": { ""key"": ""TEST"" }, ""summary"": ""Test Ticket"",

我试图通过以下代码使用JiraRESTAPI创建问题

 string data = @"{ ""fields"": {
                            ""project"":
               {
                   ""key"": ""TEST""
               },
                            ""summary"": ""Test Ticket"",
                            ""description"": ""Creating of an issue using project keys and issue type names using the REST API"",
                            ""issuetype"": {
                                ""name"": ""Bug""
                            },
                            ""assignee"": { ""xx"": ""xxx"" }
                        }
        }";
        string postUrl = "http://localhost:8080/rest/api/latest/issue/";
        System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
        client.BaseAddress = new System.Uri(postUrl);
        byte[] cred = UTF8Encoding.UTF8.GetBytes("xx:xx");
        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();

        var content = new StringContent(data, Encoding.UTF8, "application/json");
        //System.Net.Http.HttpContent content = new System.Net.Http.ObjectContent<Issue>(data, jsonFormatter);
        System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;
string data=@“{”字段“”:{
“项目”:
{
“”键“”:“”测试“”
},
“摘要”:“测试单”,
“”说明“”:“”使用REST API“”创建使用项目密钥和问题类型名称的问题,
“issuetype”:{
“名称”:“错误”
},
“受让人”:{“xx”:“xxx”}
}
}";
字符串姿势=”http://localhost:8080/rest/api/latest/issue/";
System.Net.Http.HttpClient client=新系统.Net.Http.HttpClient();
client.BaseAddress=newsystem.Uri(postrl);
byte[]cred=UTF8Encoding.UTF8.GetBytes(“xx:xx”);
client.DefaultRequestHeaders.Authorization=new System.Net.Http.Headers.AuthenticationHeaderValue(“Basic”,Convert.ToBase64String(cred));
client.DefaultRequestHeaders.Accept.Add(新的System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(“应用程序/json”);
System.Net.Http.Formatting.MediaTypeFormatter jsonFormatter=新的System.Net.Http.Formatting.JsonMediaTypeFormatter();
var content=newstringcontent(数据,Encoding.UTF8,“应用程序/json”);
//System.Net.Http.HttpContent content=新的System.Net.Http.ObjectContent(数据,jsonFormatter);
System.Net.Http.HttpResponseMessage response=client.PostAsync(“问题”,内容)。结果;

我得到了一个意外错误:“methodnotallowed”

I second@Robert,
PostAsync
的第一个参数被称为
requestUri
,因此您的
postrl
出现在这里。然后您可以跳过
BaseAddress
设置


由于您有一个
BaseAddress
和一个相对URI作为
requestUri
,HttpClient很可能将它们组合成
http://localhost:8080/rest/api/latest/issue/issue
并在实际的POST请求中使用此URL,而且该目标不允许POST。

只是一条关于url的评论:url和PostAsync呼叫中都有“问题”,您是否检查了请求指向的url?我建议使用Fiddler并检查请求url和请求正文,并使用此数据丰富您的问题RestClientIt’在RestClientJSON结构中工作良好将其放入文件并读取时出现的问题,工作正常,谢谢你,罗伯特。这是我的第二个猜测:)很高兴它能工作..你也更改了PostAsync调用吗?是的,我在PostAsync中添加了完整的url(localhost:8080/rest/api/latest/issue)