如何在Android中使用DefaultHttpClient?
android httpwebrequest apache-commons-httpclient apache-httpclient-4.x
好吧,这是交易,我编写了一个应用程序,通过HTTP(post)数据从web url请求,数据使用JSon数组返回,我解析这些数组,以获得我想要的.
直到那里使用Android 2.3.x没有问题但是当我在Android 4中测试它时它根本不起作用.
这是我的代码:
public boolean testConexio(){
boolean status = false;
String rutaServer = "URL.php";
//Log.e("log_tag", "Ruta server: "+rutaServer);
InputStream is = null;
String result = "";
String temporal;
//Valors a demanar/enviar
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("param1",config.getUserDB())); // parametros POST!
nameValuePairs.add(new BasicNameValuePair("param2",config.getPassDB())); // parametros POST!
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(rutaServer);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8")); // valors POST UTF 8 coded <-- I KNOW! this is the way i need them …Run Code Online (Sandbox Code Playgroud) android http-post http-request android-4.0-ice-cream-sandwich