我正在调用 Twitter 搜索并获得 JSON 响应。我的理解是,如果超过 twitter 请求限制,这将在 HttpResponse 代码中报告。发出请求后,如何从 HttpClient 类中获取响应代码?
还有谁知道这是否实际上是 twitter 报告超出速率限制的方式?
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
HttpGet get = new HttpGet(searchUrl);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = null;
try{
responseBody = client.execute(get, responseHandler);
// How can I get HTTP response code?
}
catch(Exception ex)
{
ex.printStackTrace();
}