android HttpClient网络通信工具类基于XML
/** * 用于建立于服务器之间通信的工具 * * * */ 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; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。