loading...

lunes, 26 de diciembre de 2011

Desde Android como Enviar una petición HTTP POST con variables

public void saveDni(String id, String dni) {   HttpClient httpclient = new DefaultHttpClient();     
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");   try {
//Añade las variables a enviar por post
List<NameValuePair> postValues = new ArrayList<NameValuePair>(2);
postValues.add(new BasicNameValuePair("id", "000001"));
postValues.add(new BasicNameValuePair("dni", "23234345T"));   httppost.setEntity(new UrlEncodedFormEntity(postValues));   //Hace la petición
HttpResponse response = httpclient.execute(httppost);
}
catch (ClientProtocolException e) {
//TODO Auto-generated catch block
}
catch (IOException e) {
//TODO Auto-generated catch block
}
}


No hay comentarios:

Publicar un comentario