使用 java 连接的 Twitter 请求失败



我可以毫无问题地提取用户的状态,但是当我与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.");

}

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();
    }
}

此请求不需要身份验证。 对不起我丑陋的代码。我的教授说输入无关紧要,所以我的I/O是火车残骸。

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

最新更新