/** * 用于建立于服务器之间通信的工具 * * * */ public class HttpClientAdapter { private HttpClient client; private HttpRequest request; private HttpGet get; private HttpPost post; private HttpResponse response; public HttpClientAdapter() { //设置client client=new DefaultHttpClient(); //设置APN信息:ip port if(StringUtils.isNotBlank(GlobalParams.IP)) { HttpHost host=new HttpHost(GlobalParams.IP, GlobalParams.PORT); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host); } } /** * 发送xml */ public InputStream sendPostRequest(String uri, String xml) { // 利用Post发送xml post = new HttpPost(uri); try { StringEntity entity = new StringEntity(xml, ConstantValue.CHARSET); post.setEntity(entity); response = client.execute(post); // 判断回复的状态码200 if (response.getStatusLine().getStatusCode() == 200) { // 获取服务器回复信息 return response.getEntity().getContent(); } } catch (Exception e) { e.printStackTrace(); } return null; } }
android HttpClient网络通信工具类基于XML
原文地址:http://blog.csdn.net/u014600432/article/details/41522073