【问题标题】:twitter API call 500 error推特 API 调用 500 错误
【发布时间】:2012-06-17 04:51:57
【问题描述】:

当 Twitter API 出现“HTTP 错误 500 内部服务器”错误时如何处理 URL 连接异常。那么如何处理它。我已经在核心 java 类中编写了这段代码并为 Twitter API 调用制作了一个包.

import java.net.*; 
import java.io.*;

public class getTwitterData {

    public static URLConnection connection;

    public static void main(String[] args) {

        try {
        System.out.println("Hello World!"); // Display the string.
            try {
            URLConnection connection = new URL("Twitter API call ").openConnection();
            InputStream response = connection.getInputStream();
            System.out.println(response);

            }
        }catch(IOException ex) {}
    }    
}

【问题讨论】:

    标签: java api exception twitter urlconnection


    【解决方案1】:

    response会有http响应码,每个响应码可以根据需要进行不同的处理。

    【讨论】:

    • 是一样的吗???? HttpURLConnection httpConn = (HttpURLConnection) 连接;输入流是; if (httpConn.getResponseCode() >= 400) { is = httpConn.getInputStream(); } else { 是 = httpConn.getErrorStream(); }
    猜你喜欢
    • 2013-06-13
    • 1970-01-01
    • 2013-11-20
    • 2017-04-17
    • 2023-01-26
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    相关资源
    最近更新 更多