相关疑难解决方法(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中的org.apache.http.conn.ConnectTimeoutException?

我正在从事与服务相关的应用程序.

DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpParams params = httpClient.getParams();
            HttpConnectionParams.setConnectionTimeout(params, 10000000);
            HttpConnectionParams.setSoTimeout(params, 15000000);
            HttpProtocolParams.setUseExpectContinue(httpClient.getParams(),true);

            String str_Server_Host = Control_PWD_Server_Name();
            String requestEnvelope = String.format(envelope_oe);
            // HttpPost httpPost = new HttpPost(str_Server_Host);
            HttpPost httpPost = new HttpPost(str_Server_Host);
            httpPost.setHeader("SOAPAction",
                    "http://tempuri.org/updateTransportStatus");
            httpPost.setHeader("Content-Type", "text/xml;charset=utf-8");
            httpPost.setEntity(new StringEntity(requestEnvelope));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();

            line = EntityUtils.toString(httpEntity);
            String str = Html.fromHtml(line).toString();
Run Code Online (Sandbox Code Playgroud)

这是我得到的例外:

org.apache.http.conn.ConnectTimeoutException: Connect to /10.64.0.184:9092 timed out
Run Code Online (Sandbox Code Playgroud)

如何解决android中的上述异常?请提供任何建议或相关的senario.

java android web-services exception connection-timeout

5
推荐指数
0
解决办法
7785
查看次数

Http响应错误android

我正在从android应用程序向cgi php服务器发出HTTP请求以获取json响应.我的应用程序在发出HTTP请求之前验证Internet连接是否可用.所有事情都正常运作.问题是我因为在发出HTTP请求后突然死于互联网连接而逐渐关闭.

所以我的问题是

  1. 我怎么理解我从服务器得到了回复?
  2. 我是否需要保持响应的时间?

android http internet-connection forceclose

1
推荐指数
1
解决办法
7266
查看次数