使用java连接的Twitter请求失败

使用java连接的Twitter请求失败,java,twitter,Java,Twitter,我可以通过cURL获取用户的状态,但当我连接Java时,xml被截断了,我的解析器想哭了。我正在测试小用户,这样就不会阻塞数据或其他任何东西 public void getRuserHx(){ System.out.println("Getting user status history..."); String https_url = "https://twitter.com/statuses/user_timeline/" + idS.rootUser + ".xml?count=10

我可以通过cURL获取用户的状态,但当我连接Java时,xml被截断了,我的解析器想哭了。我正在测试小用户,这样就不会阻塞数据或其他任何东西

public void getRuserHx(){
 System.out.println("Getting user status history...");

 String https_url = "https://twitter.com/statuses/user_timeline/" + idS.rootUser + ".xml?count=100&page=[1-32]";
 URL url;
 try {    
     url = new URL(https_url);
     HttpsURLConnection con = (HttpsURLConnection)url.openConnection(); 
     con.setRequestMethod("GET");
     con.setReadTimeout(15*1000);

     //dump all the content into an xml file
     print_content(con);

 } 
 catch (MalformedURLException e) {
     e.printStackTrace();
 } 
 catch (IOException e) {
     e.printStackTrace();
 }

 System.out.println("Finished downloading user status history.");
}


此请求不需要身份验证。对不起,我的代码太难看了。我的教授说输入不重要,所以我的I/O是一个火车残骸

写入内容时,必须刷新输出流。是否刷新或关闭了输出流?

是否确定已正确建立连接并获得了程序的输入?是的,xml正在写入,但文件每次都在同一行被截断(中间标记)。如果我在命令行中使用cURL,该文件将很好地显示出来。与Java的连接似乎无法持久。如果删除读取超时设置,会发生什么?删除超时没有任何区别。我为print方法添加了代码。我确实关闭了BufferedReader,这就是你的意思吗?我加上了.flush(),现在我想我已经找到了。谢谢
private void print_content(HttpsURLConnection con){
    if(con!=null){

    try {           
       BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));

          File userHx = new File("/" + idS.rootUser + "Hx.xml");
          PrintWriter out = new PrintWriter(idS.hoopoeData + userHx);

           String input;        
           while ((input = br.readLine()) != null){
           out.println(input);
           }

       br.close();  
    } 
    catch (IOException e) {
       e.printStackTrace();
    }

}