嗨,我一直在尝试通过 bugzilla 的 REST API 方法来搜索 bugzilla 中的错误。为了解决这些错误,我用 java 开发了代码,该代码给出了 406 错误。下面是我的代码。
public static void main(String[] args) throws IOException, JsonParser.ParseException,
JSONException, ParseException {
URL url=new URL("http:mybugzilla.com/bug");
HttpURLConnection urlConnection= (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Accept","application/json");
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
PrintStream printStream=new PrintStream(urlConnection.getOutputStream());
//printStream.print();
BufferedReader br = new BufferedReader(new
InputStreamReader(urlConnection.getInputStream()));
String line;
StringBuilder sb=new StringBuilder();
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
System.out.println(sb);
}
最佳答案
根据this Api doc您的请求字符串中可能缺少某些内容。
至少您的 URL url=new URL("http:mybugzilla.com/bug")
应该是
URL url=new URL("http://mybugzilla.com/bug")
关于java - 我如何使用 bugzilla rest api 方法/bug 列出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24279389/