我曾尝试通过Java访问GitHub以获取最新版本的存储库,我找到了this,我尝试将其用于此代码:
String url = "https://github.com/:owner/:repo/releases/latest";
try {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
request.addHeader("content-type", "application/json");
HttpResponse result = httpClient.execute(request);
String json = EntityUtils.toString(result.getEntity(), "UTF-8");
System.out.println(json);
} catch (IOException ex) {
}
并且我得到的唯一回应是网站的HTML代码,但我希望json响应就像你在exaple响应here中看到的那样。
答案 0 :(得分:1)
感谢您的帮助! 是的,它是对的,你必须访问api.github.com并且你必须设置Accept:application / vnd.github.v3 + json