我想通过 REST API 调用在 JIRA 中创建一个问题。我得到了一个示例代码和 JSON 文本。当我执行下面的代码时没有错误,但在 JIRA 中也没有创建任何问题。我使用相同的 JSON 代码在 JIRA 中使用“CURL”命令创建问题。但我未能使用下面的示例代码创建。任何人都请帮忙。
String host = "localhost";
int port = 8080;
String userName = "admin";
String password = "admin";
DefaultHttpClient httpClient = new DefaultHttpClient();
String jsonObj = "{\"fields\":" +
"{\"project\":{\"key\": \"JAVA\"}," +
"\"summary\":\"Creating issue in JIRA.\"," +
"\"description\": \"Creating of an issue using project keys and issue type names using the REST API\", " +
"\"issuetype\": {\"name\":\"Bug\"}}}";
httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port),
new UsernamePasswordCredentials(userName, password));
HttpPost httpPost = new HttpPost("http://localhost:8080/rest/api/2/issue/");
StringEntity entity = new StringEntity(jsonObj);
entity.setContentType("application/json");
httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
httpClient.getConnectionManager().shutdown();