M0286_Libro Curso
4: Web móvil en acción
parametros.get(i),
parametros.get(i + 1))); } ntity(nameValuePairs)); }
httppost.setEntity(new UrlEncodedFormE
response = httpclient.execute(httppost); entity = response.getEntity(); is = entity.getContent(); Log. e (“log_tag”, “Error in http connection “ throw new Exception(“Error al conectar con el
} catch (Exception e) {
+ e.toString());
servidor. “);
} finally {
if (entity != null) { entity = null; } ; if (response != null) { response = null; } ; if (httppost != null) { httppost = null; } ; if (httpclient != null) { httpclient = null;
} ;
}
} En el método conectaPost() hemos definido una conexión HttpPost al servidor de php pasándole los parámetros desde la clase CargaMapa . Ahora necesitamos un método que obtenga la respuesta desde el servidor y la convierta en string para posteriormente devolverla al SeasTuristicLocationZaragoza : private void getRespuestaPost() throws Exception { BufferedReader reader = null; try { reader = new BufferedReader( new InputStreamReader(is, “iso 8859-1”), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + “\n”); }
275
Made with FlippingBook - Online catalogs