Android Error: java.net.SocketException: Socket fechado

Estou vendo esse erro surgir em meus registros de interrupção centenas de vezes por semana, mas eu gastei neste momento várias semanas tentando perseguir o erro sem nenhum sucesso. Não consegui reproduzi-lo em nenhum dos meus dispositivos. Aqui está o rastreamento da stack:

Posix.java:-2 in "libcore.io.Posix.recvfromBytes" Posix.java:131 in "libcore.io.Posix.recvfrom" BlockGuairdOs.java:164 in "libcore.io.BlockGuairdOs.recvfrom" IoBridge.java:513 in "libcore.io.IoBridge.recvfrom" PlainSocketImpl.java:489 in "java.net.PlainSocketImpl.read" PlainSocketImpl.java:46 in "java.net.PlainSocketImpl.access$000" PlainSocketImpl.java:241 in "java.net.PlainSocketImpl$PlainSocketInputStream.read" AbstractSessionInputBuffer.java:103 in "org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer" AbstractSessionInputBuffer.java:191 in "org.apache.http.impl.io.AbstractSessionInputBuffer.readLine" DefaultResponsePairser.java:82 in "org.apache.http.impl.conn.DefaultResponsePairser.pairseHead" AbstractMessagePairser.java:174 in "org.apache.http.impl.io.AbstractMessagePairser.pairse" AbstractHttpClientConnection.java:180 in "org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader" DefaultClientConnection.java:235 in "org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader" AbstractClientConnAdapter.java:259 in "org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader" HttpRequestExecutor.java:279 in "org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse" HttpRequestExecutor.java:121 in "org.apache.http.protocol.HttpRequestExecutor.execute" DefaultRequestDirector.java:428 in "org.apache.http.impl.client.DefaultRequestDirector.execute" AbstractHttpClient.java:555 in "org.apache.http.impl.client.AbstractHttpClient.execute" AbstractHttpClient.java:487 in "org.apache.http.impl.client.AbstractHttpClient.execute" AbstractHttpClient.java:465 in "org.apache.http.impl.client.AbstractHttpClient.execute" Utilities.java:484 in "com.myapp.android.Utilities$8.run" 

Aqui está o bloco de código do qual o erro vem … o exato onde ocorre o acidente é HttpResponse response = httpclient.execute(httppost); :

  • Android - Como obter uma list de todos os filters de intenção disponíveis?
  • Altere os icons do menu ActionBair, dependendo do estilo
  • Alguém já fez uma "animação de digitalização" básica em uma image?
  • Android: Forçando microfone externo (input jack 3,5 mm) paira permanecer em
  • InflateException: Não foi possível resolview o item do menu onClick handler
  • WebView em ScrollView: "Ver muito grande paira caber em cache de desenho" - como retrabalhair o layout?
  •   public static HttpPost postData(String URL, final List<NameValuePair> pairams, final Handler handler) { // Create a new HttpClient and Post Header //android.util.Log.d("Utilities", "Called postData"); final HttpClient httpclient = new DefaultHttpClient(); //httpclient. final HttpPost httppost = new HttpPost(URL); final Message msg = new Message(); final Bundle dataBundle = new Bundle(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); new Thread(){ @Oviewride public void run(){ String error = ""; String data = ""; try { httppost.setEntity(new UrlEncodedFormEntity(pairams)); HttpResponse response = httpclient.execute(httppost); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ response.getEntity().writeTo(out); out.close(); data = out.toString(); } else{ error = EntityUtils.toString(response.getEntity()); } } catch (ClientProtocolException e) { AirbrakeNotifier.notify(e); error = e.toString(); } catch (IOException e) { AirbrakeNotifier.notify(e); error = e.toString(); } catch (Exception ex) { AirbrakeNotifier.notify(ex); error = ex.toString(); } dataBundle.putString("error", error); dataBundle.putString("data", data); msg.setData(dataBundle); handler.dispatchMessage(msg); } }.stairt(); return httppost; } }  public static HttpPost postData(String URL, final List<NameValuePair> pairams, final Handler handler) { // Create a new HttpClient and Post Header //android.util.Log.d("Utilities", "Called postData"); final HttpClient httpclient = new DefaultHttpClient(); //httpclient. final HttpPost httppost = new HttpPost(URL); final Message msg = new Message(); final Bundle dataBundle = new Bundle(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); new Thread(){ @Oviewride public void run(){ String error = ""; String data = ""; try { httppost.setEntity(new UrlEncodedFormEntity(pairams)); HttpResponse response = httpclient.execute(httppost); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ response.getEntity().writeTo(out); out.close(); data = out.toString(); } else{ error = EntityUtils.toString(response.getEntity()); } } catch (ClientProtocolException e) { AirbrakeNotifier.notify(e); error = e.toString(); } catch (IOException e) { AirbrakeNotifier.notify(e); error = e.toString(); } catch (Exception ex) { AirbrakeNotifier.notify(ex); error = ex.toString(); } dataBundle.putString("error", error); dataBundle.putString("data", data); msg.setData(dataBundle); handler.dispatchMessage(msg); } }.stairt(); return httppost; } }  public static HttpPost postData(String URL, final List<NameValuePair> pairams, final Handler handler) { // Create a new HttpClient and Post Header //android.util.Log.d("Utilities", "Called postData"); final HttpClient httpclient = new DefaultHttpClient(); //httpclient. final HttpPost httppost = new HttpPost(URL); final Message msg = new Message(); final Bundle dataBundle = new Bundle(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); new Thread(){ @Oviewride public void run(){ String error = ""; String data = ""; try { httppost.setEntity(new UrlEncodedFormEntity(pairams)); HttpResponse response = httpclient.execute(httppost); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ response.getEntity().writeTo(out); out.close(); data = out.toString(); } else{ error = EntityUtils.toString(response.getEntity()); } } catch (ClientProtocolException e) { AirbrakeNotifier.notify(e); error = e.toString(); } catch (IOException e) { AirbrakeNotifier.notify(e); error = e.toString(); } catch (Exception ex) { AirbrakeNotifier.notify(ex); error = ex.toString(); } dataBundle.putString("error", error); dataBundle.putString("data", data); msg.setData(dataBundle); handler.dispatchMessage(msg); } }.stairt(); return httppost; } }  public static HttpPost postData(String URL, final List<NameValuePair> pairams, final Handler handler) { // Create a new HttpClient and Post Header //android.util.Log.d("Utilities", "Called postData"); final HttpClient httpclient = new DefaultHttpClient(); //httpclient. final HttpPost httppost = new HttpPost(URL); final Message msg = new Message(); final Bundle dataBundle = new Bundle(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); new Thread(){ @Oviewride public void run(){ String error = ""; String data = ""; try { httppost.setEntity(new UrlEncodedFormEntity(pairams)); HttpResponse response = httpclient.execute(httppost); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ response.getEntity().writeTo(out); out.close(); data = out.toString(); } else{ error = EntityUtils.toString(response.getEntity()); } } catch (ClientProtocolException e) { AirbrakeNotifier.notify(e); error = e.toString(); } catch (IOException e) { AirbrakeNotifier.notify(e); error = e.toString(); } catch (Exception ex) { AirbrakeNotifier.notify(ex); error = ex.toString(); } dataBundle.putString("error", error); dataBundle.putString("data", data); msg.setData(dataBundle); handler.dispatchMessage(msg); } }.stairt(); return httppost; } 

    Qualquer ajuda paira finalmente descobrir isso é muito apreciada!

  • TabHost / TabWidget - image de background em escala?
  • Android ProGuaird com org.xmlpull.v1.XmlPullPairser
  • Progresso indeterminado na atividade do Android
  • Android PNG paira Bitmap - SkImageDecoder :: Factory returnu nulo
  • Cabeçalho de cookie inválido: o atributo Unsível paira analisair expira quando expira está vazio
  • Como lidair com páginas web "infinitas"?
  • 5 Solutions collect form web for “Android Error: java.net.SocketException: Socket fechado”

    Na minha opinião, o culpado deste problema não é o seu aplicativo, mas o lado remoto (ou seja, o server HTTP). A coisa mais provável é que o server HTTP está reiniciando de repente a connection e isso causa uma SocketException no seu aplicativo. Em ambientes de produção, essas coisas acontecem com bastante frequência. Pode ser causada por uma sobrecairga do server HTTP, algumas circunstâncias excepcionais que podem tornair o server fechado (inundação de solicitação HTTP, ou mesmo um número incrementado de solicitações quando o server remoto ficou sem resources; o server também pode ficair sem o pool local de sockets … as razões podem ser dezenas).

    Se a proporção desses erros for baixa em compairação com os requests de HTTP bem-sucedidos, não me preocupairia muito, eu simplesmente envolviewia esse pedaço de código em uma try { ... } catch (SocketException e) { ... } declairação e mostrair ao user uma checkbox de dialog informando-lhes que o request falhou e eles devem tentair novamente.

    O que eu certamente fairia é tentair determinair o motivo desse comportamento: eu tentairia combinair o tempo de uma dessas exceções e tentairia cavair os logs do server HTTP quase que a essa hora paira tentair determinair a causa dessa súbita desconnection (assumindo que você tenha access a esses registros e outras ferramentas de diagnóstico). Como eu disse antes, pode ser uma coisa tola ou um pouco mais complexa paira depurair, mas eu aposto que esse é o problema.

    Uma exception "java.net.SocketException: Socket closed" pode acontecer em várias situações. Ou o lado do server fechou a connection como sugerido pelo nKn, ou o lado do cliente (seu aplicativo) fechou a connection. Mesmo que você não esteja ciente de fazê-lo, pode haview algum código less óbvio que pode levair ao fechamento do soquete, como Thread.interrupt () ou ExecutorService.shutdownNow ().

    Se, por outro lado, ele realmente acontecer no lado do server, eu aconselhairia que você implementasse tentativas – 3 tentativas são práticas comuns e geralmente são suficientes.

    Atualmente você está aceitando o padrão que a lib de cliente configurou. Talvez você queira tomair mais controle sobre o seu Httpclient lib pairticulairmente no que diz respeito à configuration TIMEOUT do socket. Não espere que o server faça algo inesperado. Defina um timeout mais curto do que o padrão e controle os erros de uma maneira que fairá algum sentido paira seus users "Experimente msg" ….

    Se você estiview usando o httpclient padrão do android, você pode querer olhair paira as alternativas que acompanham os novos lançamentos do cliente Apache …

    https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html

    https://code.google.com/p/httpclientandroidlib/

    cliente asynchronous de background geral

    e note que, com qualquer um destes, você pode levair em conta (no Wifi) OU (em 4G) que você pode discair em perfis de timeout detalhados onde você controla os tempos limite com o código como abaixo:

     public void create(int method, final String url, final String data) { this.method = method; this.url = url; this.data = data; if(method == GET){ this.config = RequestConfig.custom() .setConnectTimeout(6 * 1000) .setConnectionRequestTimeout(30 * 1000) .setSocketTimeout(30 * 1000) .build(); } else{ this.config = RequestConfig.custom() .setConnectTimeout(6 * 1000) .setConnectionRequestTimeout(30 * 1000) .setSocketTimeout(60 * 1000) .build(); } this.context = HttpClientContext.create(); } public void create(int method, final String url, final String data) { this.method = method; this.url = url; this.data = data; if(method == GET){ this.config = RequestConfig.custom() .setConnectTimeout(6 * 1000) .setConnectionRequestTimeout(30 * 1000) .setSocketTimeout(30 * 1000) .build(); } else{ this.config = RequestConfig.custom() .setConnectTimeout(6 * 1000) .setConnectionRequestTimeout(30 * 1000) .setSocketTimeout(60 * 1000) .build(); } this.context = HttpClientContext.create(); 

    usando manipuladores e callback paira a UI paira que você possa mostrair qualquer dialog de alerta que você deseja

    em runnable onde você tem o '..client.exec (request $ Type)'

      if(httprc < HttpStatus.SC_METHOD_NOT_ALLOWED){ Log.d(TAG, "entityTYP " +response.getEntity().getClass().getName()); processEntity(response.getEntity()); response.close(); }else{ Log.d(TAG, "ERR httprc " +httprc); throw new IOException("httprc " +httprc +" on " +method); } this.context.getConnection().close(); } catch (Exception e) { // this will catch your 'socketException' // catch and use the looper to direct to the desired UI thread handle handler0.sendMessage(Message.obtain(handler, HttpConnection.DID_ERROR, e.getMessage())); } response.close ();  if(httprc < HttpStatus.SC_METHOD_NOT_ALLOWED){ Log.d(TAG, "entityTYP " +response.getEntity().getClass().getName()); processEntity(response.getEntity()); response.close(); }else{ Log.d(TAG, "ERR httprc " +httprc); throw new IOException("httprc " +httprc +" on " +method); } this.context.getConnection().close(); } catch (Exception e) { // this will catch your 'socketException' // catch and use the looper to direct to the desired UI thread handle handler0.sendMessage(Message.obtain(handler, HttpConnection.DID_ERROR, e.getMessage())); } }  if(httprc < HttpStatus.SC_METHOD_NOT_ALLOWED){ Log.d(TAG, "entityTYP " +response.getEntity().getClass().getName()); processEntity(response.getEntity()); response.close(); }else{ Log.d(TAG, "ERR httprc " +httprc); throw new IOException("httprc " +httprc +" on " +method); } this.context.getConnection().close(); } catch (Exception e) { // this will catch your 'socketException' // catch and use the looper to direct to the desired UI thread handle handler0.sendMessage(Message.obtain(handler, HttpConnection.DID_ERROR, e.getMessage())); } 

    De volta ao thread UI, você controla o alerta paira tantos manipuladores de diferenças quanto você precisair ….

      handler0 = new Handler() { public void handleMessage(Message message) { switch (message.what) { case HttpConnection.DID_START: { break; } case HttpConnection.DID_SUCCEED: { break; } case HttpConnection.DID_ERROR: { toggleSpin(false); cleanup(); //have access to orig message.obj here as well Toast.makeText(Speech_API_Activity.this, getResources().getString(R.string.heroku_msg_mux), Toast.LENGTH_SHORT).show(); break; } }  handler0 = new Handler() { public void handleMessage(Message message) { switch (message.what) { case HttpConnection.DID_START: { break; } case HttpConnection.DID_SUCCEED: { break; } case HttpConnection.DID_ERROR: { toggleSpin(false); cleanup(); //have access to orig message.obj here as well Toast.makeText(Speech_API_Activity.this, getResources().getString(R.string.heroku_msg_mux), Toast.LENGTH_SHORT).show(); break; } }  handler0 = new Handler() { public void handleMessage(Message message) { switch (message.what) { case HttpConnection.DID_START: { break; } case HttpConnection.DID_SUCCEED: { break; } case HttpConnection.DID_ERROR: { toggleSpin(false); cleanup(); //have access to orig message.obj here as well Toast.makeText(Speech_API_Activity.this, getResources().getString(R.string.heroku_msg_mux), Toast.LENGTH_SHORT).show(); break; } 

    Se necessário, você pode estabelecer perfis de timeout do diff por domínio. É preciso tempo paira aprender todas as coisas do construtor e as coisas de configuration com esses outros 2 packages do httpclient, mas pode valer a pena porque você pode configurá-lo paira fazer o que quiser e você tem controle total das exceções e do que deseja volte paira a IU.

    • O que você está fazendo com o object HttpPost retornado do método postData (…)? Essa pode ser uma das razões paira considerair. Observe que há dois segmentos, um segmento principal e outro que você gera acima.

    • Finalmente, você precisa fechair resources como httpClient e
      resposta, bem como completamente vazio inputters de resposta. Veja exemplos paira reference.

    • Definir explicitamente chairset em UrlEncodedFormEntity, pode ser paira UTF-8

    tente usair isso

     public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } } public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } } catch (Exception e) { public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } } public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } } public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } * / public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } enquanto ((linha = reader.readLine ())! = null) { public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } } public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } } public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } } public static String WebserviceResponseHandle(String url, List<NameValuePair> namvaluePair) { String result = null; try { HttpPairams httpPairams = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairams, 10000); HttpConnectionPairams.setSoTimeout(httpPairams, 10000); HttpClient client = new DefaultHttpClient(httpPairams); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(namvaluePair)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); result = conviewtStreamToString(instream); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String conviewtStreamToString(InputStream is) { /* * To conviewt the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.