Conexão Http

Boa Tarde.

Criei no Eclipse uma Aplicação Web com um arquivo Xml para ser baixado pelo Android. A aplicação no android baixa o arquivo e grava no sdCard do emulador tudo funcionando blz. Mas se eu derrubar a aplicação Web a aplicação no android ao tentar baixar o arquivo trava e eu não encontrei uma maneira de tratar esse problema.

A pergunta é: Como eu faço para testar se a conexão foi bem sucedida.

Ps: desculpa não poder colocar o codígo mas estou sem net em casa e esqueci de traze-lo :smiley:

se vc estiver usando apache httpclient:


  
  private static String url = "http://www.apache.org/";


    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(url);
    
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
    		new DefaultHttpMethodRetryHandler(3, false));

    try {
      // Execute the method.
      int statusCode = client.executeMethod(method);

      if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
      }

      // Read the response body.
      byte[] responseBody = method.getResponseBody();

      // Deal with the response.


    } catch (HttpException e) {

      e.printStackTrace();
    } catch (IOException e) {

      e.printStackTrace();
    } finally {
      // Release the connection.
      method.releaseConnection();
    }  
  }

a variavel statusCode recebe o codigo do resultado da requisição,que se for 200 significa que foi executada com sucesso.

E se for pelo HttpUrlConnection:

try {
  URL url = new URL("http://www.google.com");
  HttpURLConnection con = (HttpURLConnection) url
    .openConnection();
    int statusCode = con.getResponseCode();

  } catch (Exception e) {
  e.printStackTrace();
}

E é a mesma coisa,ai vc tem que verificar se é igual a 200,ai vc pode usar essa constante HttpURLConnection.HTTP_OK.