我想通过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();
答案 0 :(得分:0)
尝试使用此代码...
String project ="JAVA";
String summary ="your summary";
String description ="your description";
String issueType ="Bug";
String jsonObj ="{\"fields\": { \"project\": { \"key\": " + "\"" + project + "\"}, "+
"\"summary\": " + "\"" + summary + "\", "+
"\"description\": " + "\"" + description + "\", "+
"\"issuetype\": { \"name\": \"" + issueType + "\"}}} "