ramon00
22/04/13, 15:45:19
Buenas necesito resolver otra duda a ver si alguien la sabe.
Tengo un script en php que entre otras cosas devuelve los datos que le envio , de la siguiente forma, si entro con un navegador en la direccion:
"http://www.pagina.com/script.php?img=imagen.jpg&res=M";
me muestra por pantalla el texto: "imagen.jpg M".
Ahora necesito hacer lo mismo con android, hacer una petición con los parametros img y res y leer la respuesta que devuelva el php, el código que tengo escrito para hacer esto es este:
public void enviarDatos(View v) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.pagina.com/carpeta1/carpeta2/script.php");
try {
List <NameValuePair> nameValuePairs = new ArrayList <NameValuePair> (2);
nameValuePairs.add(new BasicNameValuePair("img", "imagen"));
nameValuePairs.add(new BasicNameValuePair("res", "M"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
InputStream is = response.getEntity().getContent();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
/* Convert the Bytes read to a String. */
text = new String(baf.toByteArray());
result.setText(text);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
pero me devuelve esto:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>403 Forbidden</title></head><body><h1>Forbidden</h1><p>You don't have permission to access /carpeta1/carpeta2/script.phpon this server.</p><hr><address>Apache/2.2.22 (Ubuntu) Server at www.pagina.com (http://www.pagina.com) Port 80</address></body></html>
Parece un problema de permisos , pero por otra parte si puedo hacer lo que quiero con el navegador(firefox). Gracias por leerlo.
Tengo un script en php que entre otras cosas devuelve los datos que le envio , de la siguiente forma, si entro con un navegador en la direccion:
"http://www.pagina.com/script.php?img=imagen.jpg&res=M";
me muestra por pantalla el texto: "imagen.jpg M".
Ahora necesito hacer lo mismo con android, hacer una petición con los parametros img y res y leer la respuesta que devuelva el php, el código que tengo escrito para hacer esto es este:
public void enviarDatos(View v) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.pagina.com/carpeta1/carpeta2/script.php");
try {
List <NameValuePair> nameValuePairs = new ArrayList <NameValuePair> (2);
nameValuePairs.add(new BasicNameValuePair("img", "imagen"));
nameValuePairs.add(new BasicNameValuePair("res", "M"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
InputStream is = response.getEntity().getContent();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
/* Convert the Bytes read to a String. */
text = new String(baf.toByteArray());
result.setText(text);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
pero me devuelve esto:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>403 Forbidden</title></head><body><h1>Forbidden</h1><p>You don't have permission to access /carpeta1/carpeta2/script.phpon this server.</p><hr><address>Apache/2.2.22 (Ubuntu) Server at www.pagina.com (http://www.pagina.com) Port 80</address></body></html>
Parece un problema de permisos , pero por otra parte si puedo hacer lo que quiero con el navegador(firefox). Gracias por leerlo.