2014-11-21 25 views
0

的當我與XML鍵入此以下網址進入我的瀏覽器,Bugzilla的答案:的Bugzilla查詢使用Java - 獲取HTML而不是XML

http://bugzilla.mycompany.local/buglist.cgi?ctype=rdf&bug_status=CONFIRMED&product=MyProduct 

我想處理此XML的Java程序。但是當我在我的Java程序中使用完全相同的URL時,Bugzilla用HTML而不是XML來回答。

這是我的計劃:

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.net.URL; 
import java.net.URLConnection; 

public class Test { 
    public static void main(String[] args) 
      throws IOException { 
     URL url = new URL("http://bugzilla.mycompany.local/buglist.cgi?ctype=rdf&bug_status=CONFIRMED&product=MyProduct"); 
     URLConnection connection = url.openConnection(); 
     final StringBuilder response = new StringBuilder(1024); 
     try(InputStreamReader isr = new InputStreamReader(connection.getInputStream())) { 
      try(BufferedReader reader = new BufferedReader(isr)) { 
       String inputLine = null; 
       while((inputLine = reader.readLine()) != null) { 
        response.append(inputLine); 
        response.append('\n'); 
       } 
      } 
     } 
     System.out.println(response); 
    } 
} 

我在做什麼錯?

+0

你得到了什麼html?在大多數情況下,我遇到過這樣的行爲是與一些安全/認證相關的 – Nadir 2014-11-21 09:04:29

+0

我認爲html會是查詢的結果。你的問題讓我看起來更接近。 Bugzilla希望我提供用戶名和密碼。謝謝! – user2995410 2014-11-21 09:23:44

回答

0

生成的HTML不是查詢的結果。它是Bugzillas登錄表單。咄!