使用jira api获取指定项目的所有版本
Using jira api to get all version for a specified project
我有下面的代码,可以处理我的 Jira URL 中的一些项目,但不能处理所有项目,但我可以访问所有这些项目。我不明白为什么这段代码没有为我的所有项目提供正确答案。
当我尝试一个不工作的项目时,我在 JSON 格式中的响应将是:
{
"errorMessages": [
"No project could be found with key 'CRAFTIDGDS'."
],
"errors": {}
}
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
URI uri = URI.create(JiraProperties.getInstance().getJiraUrl() + "rest/api/2/project/" + jiraProject.getProjectName() + "/versions");
HttpGet httpGet = new HttpGet(uri);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
您提供的代码示例中没有身份验证,所以我猜您是在匿名检索信息。
如果您添加基本身份验证并使用具有适当权限的用户,那么您应该会得到结果。
就像 GlennV 说我的代码中没有身份验证,所以我添加了它,它工作得很好:
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urlRequest);
httpGet.addHeader(BasicScheme.authenticate(
new UsernamePasswordCredentials(JiraProperties.getInstance().getJiraUsername(), JiraProperties.getInstance().getJiraPassword()),
"UTF-8", false));
HttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpGet);
} catch (IOException e) {
e.printStackTrace();
}
return httpResponse.getEntity();
我有下面的代码,可以处理我的 Jira URL 中的一些项目,但不能处理所有项目,但我可以访问所有这些项目。我不明白为什么这段代码没有为我的所有项目提供正确答案。 当我尝试一个不工作的项目时,我在 JSON 格式中的响应将是:
{
"errorMessages": [
"No project could be found with key 'CRAFTIDGDS'."
],
"errors": {}
}
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
URI uri = URI.create(JiraProperties.getInstance().getJiraUrl() + "rest/api/2/project/" + jiraProject.getProjectName() + "/versions");
HttpGet httpGet = new HttpGet(uri);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
您提供的代码示例中没有身份验证,所以我猜您是在匿名检索信息。
如果您添加基本身份验证并使用具有适当权限的用户,那么您应该会得到结果。
就像 GlennV 说我的代码中没有身份验证,所以我添加了它,它工作得很好:
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urlRequest);
httpGet.addHeader(BasicScheme.authenticate(
new UsernamePasswordCredentials(JiraProperties.getInstance().getJiraUsername(), JiraProperties.getInstance().getJiraPassword()),
"UTF-8", false));
HttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpGet);
} catch (IOException e) {
e.printStackTrace();
}
return httpResponse.getEntity();