Ver Mensaje Individual
  #4 (permalink)  
Antiguo 30/09/2013, 07:09
nrzlftw
 
Fecha de Ingreso: septiembre-2012
Mensajes: 17
Antigüedad: 11 años, 8 meses
Puntos: 0
Exclamación Respuesta: Consumir servicios php

Muchas gracias por vuestra respuesta. Necesito terminar esto para mañana y me va a dar algo ya que soy un poco(Bastante)nuevo en el tema de Java y Android

Actualmente tengo esto:

String sym.getData = "hello";
String txt = QRpost.postData();

Código:
if(txt.equals(sym.getData())){ 
     //Todo correcto
    }else{
     //Hubo un error
    }
El código con el que conecto con el archivo PHP:

Código:
    public class QRpost {
	public static String postData() {
		String result = "";
		
	    // Create a new HttpClient and Post Header
	    HttpClient httpclient = new DefaultHttpClient();
	    HttpPost httppost = new HttpPost("http://server/qr.php");
	    try {
	        // Execute HTTP Post Request
	        HttpResponse response = httpclient.execute(httppost);
	        HttpEntity entity = response.getEntity();
	        InputStream webs = entity.getContent();
	        try{
	         BufferedReader reader = new BufferedReader(new InputStreamReader(webs,"iso-8859-1"),8);
	        	//scanText.setText(reader.readLine()); //Read line
	        	StringBuilder builder = new StringBuilder();
	            String line = null;

	            while ((line = reader.readLine()) != null) {

	                builder.append(line);
	            }

	            webs.close();

	            String json = builder.toString();
	            
	        }catch(Exception e){
	        	Log.e("log_tag", "Error to convert result");
	        }
	    } catch (ClientProtocolException e) {
	        // TODO Auto-generated catch block
	    } catch (IOException e) {
	        // TODO Auto-generated catch block
	    }
	    try{
	    	JSONArray jArray = new JSONArray(result);
	    	for(int i=0;i<jArray.length();i++){
	    		JSONObject json_data = jArray.getJSONObject(i);
	    		Log.e("log_tag", json_data.getString("codeqr"));
	    	}
	    }catch(JSONException e){
	    	
	    }
		return result;
	}
     }
¿Me podéis decir si por ahora voy bien?¿Cambiaríais algo?