android httpPost 的请求

来源:互联网 发布:知乎大神 微博 编辑:程序博客网 时间:2024/04/29 16:44
final Handler handle = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String obj = (String) msg.obj; if (BaseApplication.getInstanse() != null) { if (BaseApplication.getInstanse() .getiLoadImageCloas() != null) { BaseApplication.getInstanse() .getiLoadImageCloas() .imageCloase(obj); } } } }; new Thread() { @Override public void run() { Looper.prepare(); try { ArrayList paramsValue = new ArrayList(); //对Post的请求数据进行封装成字典paramsValue.add(new BasicNameValuePair(“p”, json.toString())); paramsValue.add(new BasicNameValuePair(“t”, “code”)); paramsValue.add(new BasicNameValuePair(“a”, “code”)); HttpResponse response = HttpClientUtils //Post的请求方式.httpPost(HostUrl, null, paramsValue); if (response != null) { try { String strResult = EntityUtils .toString(response .getEntity()); Message message = new Message(); message.obj = strResult; handle.sendMessage(message); //数据回传handle来管理刷新界面} catch (Exception exception) { exception.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } Looper.loop(); } }.start(); }

看代码效果,主要post数据封装







0 0