Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/08/2015, 00:20
banderas20
 
Fecha de Ingreso: noviembre-2003
Mensajes: 456
Antigüedad: 20 años, 6 meses
Puntos: 1
Pregunta Envío de datos de Android a servidor web

Buenas,

estoy haciendo una pequeña aplicación que envíe datos desde Android a un servidor web y lo guarde en una BBDD.

Mi código es el siguiente:

Código:
     public void envia(View v) {
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://x.y.z.a/android1/new_record.php");
            TextView tv = (TextView) findViewById(R.id.logbox);
    //        tv.setText(String.valueOf(cambios));
            strLog="Dentro de función...";
            tv.setText(strLog);

            try {
                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("fecha", "2015-08-02 02:09:12"));
                nameValuePairs.add(new BasicNameValuePair("valor", "1"));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);

            } catch (org.apache.http.client.ClientProtocolException e) {
                // TODO Auto-generated catch block
                strLog=strLog+ "http_Err" + e.toString();
            } catch (java.io.IOException e) {
                // TODO Auto-generated catch block
                strLog=strLog+ "IO_Err" + e.toString();
            }
            tv.setText(strLog);

        }
He hecho un log, y me da el error:

Código:
    httpHostConnectException: Connection to http://IP refused

No lo entiendo, porque si abro un navegador y le pongo la URL, me abre la web...

¿alguna idea?

Gracias!

Última edición por banderas20; 02/08/2015 a las 16:34 Razón: Repaso