I need to get information from php web service, but when I do HttpPost in android The application breaks jusrt in HttpResponse response = httpclient.execute(httppost);
this is my Android code
public String getHttp(){
String jsonResult ="";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://ift.tt/1OsSjeZ");
try {
HttpResponse response = httpclient.execute(httppost);
jsonResult = convertStreamtoString(
response.getEntity().getContent()).toString();
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return jsonResult;
}
private String convertStreamtoString(InputStream resultado) throws IOException{
if(resultado != null){
StringBuilder sb = new StringBuilder();
String con = "";
try{
BufferedReader br = new BufferedReader(
new InputStreamReader(resultado, "UTF-8"));
while((con = br.readLine())!= null){
sb.append(con).append("'n");
}
}finally{
resultado.close();
}
return sb.toString();
}
else{
return "";
}
}
and this is my PHP code
<?php
include ('conex.php');
$result = mysql_query("Select nombre FROM escuela") or die("No se realizo");
$json = array();
if(mysql_num_rows($result)){
while ($row = mysql_fetch_assoc($result)) {
$json[]= $row;
}
}
echo json_encode($json);
?>
I hope you can help me, thank you
Aucun commentaire:
Enregistrer un commentaire