標籤:網路 通訊 android 伺服器
/** * 用於建立於伺服器之間通訊的工具 * * * */public class HttpClientAdapter {private HttpClient client;private HttpRequest request;private HttpGet get;private HttpPost post;private HttpResponse response;public HttpClientAdapter(){//設定clientclient=new DefaultHttpClient();//設定APN資訊:ip portif(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發送xmlpost = new HttpPost(uri);try {StringEntity entity = new StringEntity(xml, ConstantValue.CHARSET);post.setEntity(entity);response = client.execute(post);// 判斷回複的狀態代碼200if (response.getStatusLine().getStatusCode() == 200) {// 擷取伺服器回複資訊return response.getEntity().getContent();}} catch (Exception e) {e.printStackTrace();}return null;}}
android HttpClient網路通訊工具類基於XML