English 中文(简体)
连接 java 的推特请求失败
原标题:Twitter request with java connection fails
  • 时间:2012-05-23 06:12:24
  •  标签:
  • 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=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是一个火车事故。

最佳回答

写入内容时, 您必须冲洗输出流 。 您是冲洗还是关闭输出流?

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签