如何在Java中为Android设置HttpResponse超时
2022-08-31 04:56:37
我创建了以下函数来检查连接状态:
private void checkConnectionStatus() {
HttpClient httpClient = new DefaultHttpClient();
try {
String url = "http://xxx.xxx.xxx.xxx:8000/GaitLink/"
+ strSessionString + "/ConnectionStatus";
Log.d("phobos", "performing get " + url);
HttpGet method = new HttpGet(new URI(url));
HttpResponse response = httpClient.execute(method);
if (response != null) {
String result = getResponse(response.getEntity());
...
当我关闭服务器进行测试时,执行在行中等待很长时间
HttpResponse response = httpClient.execute(method);
有谁知道如何设置超时以避免等待太久?
谢谢!