相关疑难解决方法(0)

如何在Java中为Android设置HttpResponse超时

我创建了以下用于检查连接状态的函数:

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());
        ...
Run Code Online (Sandbox Code Playgroud)

当我关闭服务器进行测试时,执行会等待很长时间

HttpResponse response = httpClient.execute(method);
Run Code Online (Sandbox Code Playgroud)

有谁知道如何设置超时以避免等待太久?

谢谢!

java android timeout httpresponse

332
推荐指数
5
解决办法
19万
查看次数

标签 统计

android ×1

httpresponse ×1

java ×1

timeout ×1