我有下面的代码,它正在使用我的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();
}
答案 0 :(得分:1)
您提供的代码示例中没有身份验证,因此我猜您正在匿名检索信息。
如果您添加基本身份验证并使用具有适当权限的用户,那么您应该获得结果。
答案 1 :(得分:1)
就像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();