首页 > 解决方案 > Java 通过 SSO 从 Rest API Jira 获取 json

问题描述

我想从我们的 Jira API Rest 中获取数据。有 SSO,我会自动使用我的 Windows 用户登录。

当我调用主页(https://jira.f.bbg/rest/api/2/search?jql)时: - 使用我的 java 代码: {"startAt":0,"maxResults":50,"total": 0,"issues":[]} - 在私人导航中使用我的浏览器:{"startAt":0,"maxResults":50,"total":0,"issues":[]} - 使用我的浏览器:我得到了我想从 api 获得的数据

当我使用参数(https://jira.f.bbg/rest/api/2/search?jql=project=PARE2)调用 API 时: - 使用我的 java 代码:java.io.IOException:服务器返回 HTTP 响应代码:400 - 在私人导航中使用浏览器:{“errorMessages”:[“La valeur 'PARE2' n'existe pas pour le champ'project'。”],“错误”:{}} - 使用我的浏览器:我得到了我想从 api 获得的数据

我尝试了很多东西,一开始遇到 SSL 问题,我使用了 jks,现在可以了。我真的不明白为什么我无法获取数据,以及为什么当我有 url 参数时出现错误 400 :(

  public String recuperer(String adresse) throws Exception {
    URL url = new URL(adresse);

HttpsURLConnection.setDefaultSSLSocketFactory(SecuriteHelper.getSslContext().getSocketFactory());
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();

con.setRequestMethod("GET");
con.setRequestProperty("Accept-Charset", "UTF-8");
con.setRequestProperty("Accept", "application/json");

StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
for (String line; (line = reader.readLine()) != null;) {
  sb.append(line);
}

return sb.toString();

}

标签: javajsonresturljira

解决方案


推荐阅读