我如何使用bugzilla rest api方法/bug来列出bug



你好,我一直在尝试通过bugzilla的rest api方法搜索bugzilla中的bug。为了得到错误,我在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);
}

根据此Api文档,您可能在请求字符串中缺少某些内容。至少你的URL url=new URL("http:mybugzilla.com/bug")应该是

URL URL =new URL("http://mybugzilla.com/bug")

用python编写的示例,用于获取Bugzilla 5中的公共错误列表。

import requests
url_bz_restapi = 'http://localhost/bugzilla/rest.cgi/bug'
r = requests.get(url_bz_restapi)

最新更新