嘿伙计们,我真的很难解决这个问题,我想通过 REST API 使用 java 创建新的 JIRA 问题,但我看到的每个示例都不完整或不适合我,如下所示:如何使用 java rest api 在 jira 中创建问题 https://stackoverflow.com/questions/32308456/how-to-create-an-issue-in-jira-using-java-rest-api
任何帮助、示例代码或正确方向的链接将不胜感激!
我认为这个示例代码对你有帮助
这对我来说完全有效
public static String invokePostMethod() throws AuthenticationException, ClientHandlerException, IOException {
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/rest/api/latest/issue");
String data = "{"fields":{"project":{"key":"DEMO"},"summary":"REST Test","issuetype":{"name":"Bug"}}}";
String auth = new String(Base64.encode(Uname + ":" + Password));
ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").post(ClientResponse.class, data);
int statusCode = response.getStatus();
if (statusCode == 401) {
throw new AuthenticationException("Invalid Username or Password");
} else if (statusCode == 403) {
throw new AuthenticationException("Forbidden");
} else if (statusCode == 200 || statusCode == 201) {
System.out.println("Ticket Create succesfully");
} else {
System.out.print("Http Error : " + statusCode);
}
// ******************************Getting Responce body*********************************************
BufferedReader inputStream = new BufferedReader(new InputStreamReader(response.getEntityInputStream()));
String line = null;
while ((line = inputStream.readLine()) != null) {
System.out.println(line);
}
return response.getEntity(String.class);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)