异常超时连接到服务器

时间:2013-05-16 02:06:19

标签: android androidhttpclient

我正在做一个连接到服务器的应用程序,下一个代码工作正常:

  class Post {      
    private InputStream is = null;
    private String respuesta = "";

    private void conectaPost(ArrayList parametros, String URL) {
        ArrayList nameValuePairs;           
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(URL);
            nameValuePairs = new ArrayList();

            if (parametros != null) {
                for (int i = 0; i < parametros.size() - 1; i += 2) {
                    nameValuePairs.add(new BasicNameValuePair((String)parametros.get(i), (String)parametros.get(i + 1)));

                }                   
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            }

            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection " + e.toString());

        } finally {}

    }

连接正常,但是当服务器关闭时,应用程序将被销毁并且不会显示异常或消息“连接错误”。

0 个答案:

没有答案