我正在尝试使用 RestSharp 发出 POST 请求以在 JIRA 中创建问题,而我必须使用的是一个使用 cURL 的示例。我对这两者都不够熟悉,不知道我做错了什么。
这是example https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue在 cURL 中给出:
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json"
http://localhost:8090/rest/api/2/issue/
这是他们的示例数据:
{"fields":{"project":{"key":"TEST"},"summary":"REST ye merry gentlemen.","description":"Creating of an issue using project keys and issue type names using the REST API","issuetype":{"name":"Bug"}}}
这是我尝试使用 RestSharp 进行的操作:
RestClient client = new RestClient();
client.BaseUrl = "https://....";
client.Authenticator = new HttpBasicAuthenticator(username, password);
....// connection is good, I use it to get issues from JIRA
RestRequest request = new RestRequest("issue", Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("data", request.JsonSerializer.Serialize(issueToCreate));
request.RequestFormat = DataFormat.Json;
IRestResponse response = client.Execute(request);
我得到的是 415 响应
Unsupported Media Type
注意:我也尝试了中建议的内容这个帖子 https://stackoverflow.com/questions/11400879/how-to-post-request-using-restsharp,但这并没有解决问题。任何指导表示赞赏!