cristina1991
25/02/13, 16:17:04
Hola buenas, estoy intentando hacer una conexion con respuesta a una página con https, y no consigo que funcione... este es el código que estoy usando:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity ;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import android.util.Log;
public class ConsultaTarjeta{
public static String callRESTService(String NumTarjeta) {
String html = null;
try{
HttpPost httpost = new HttpPost("https://www.tarjeta.com.pa/consultatpv/ConsultaTPVAction.do");
List<NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("mtd", "doBuscaPlaca"));
nvps.add(new BasicNameValuePair("wte_nro_placa", NumTarjeta));
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpost);
HttpEntity entity = response.getEntity();
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
readFromBuffer(new BufferedReader(new InputStreamReader(entity.getContent(),"UTF-8")));
Log.e("respuesta",html);
return html;
} catch(Exception e){
e.printStackTrace();
html="error de lectura";
Log.e("respuesta",html);
}
return html;
}
private static String readFromBuffer(BufferedReader br){
StringBuilder text = new StringBuilder();
try{
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
// tratar excepción!!!
}
return text.toString();
}
}
Si alguien puede ayudarme y decirme cual es el fallo, o que protocolo necesito para conectar con la página o algo se lo agradezco. Un saludo.:gracias:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity ;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import android.util.Log;
public class ConsultaTarjeta{
public static String callRESTService(String NumTarjeta) {
String html = null;
try{
HttpPost httpost = new HttpPost("https://www.tarjeta.com.pa/consultatpv/ConsultaTPVAction.do");
List<NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("mtd", "doBuscaPlaca"));
nvps.add(new BasicNameValuePair("wte_nro_placa", NumTarjeta));
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpost);
HttpEntity entity = response.getEntity();
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
readFromBuffer(new BufferedReader(new InputStreamReader(entity.getContent(),"UTF-8")));
Log.e("respuesta",html);
return html;
} catch(Exception e){
e.printStackTrace();
html="error de lectura";
Log.e("respuesta",html);
}
return html;
}
private static String readFromBuffer(BufferedReader br){
StringBuilder text = new StringBuilder();
try{
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
// tratar excepción!!!
}
return text.toString();
}
}
Si alguien puede ayudarme y decirme cual es el fallo, o que protocolo necesito para conectar con la página o algo se lo agradezco. Un saludo.:gracias: