码迷,mamicode.com
首页 > 移动开发 > 详细

android HttpClient网络通信工具类基于XML

时间:2014-11-26 22:44:37      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:网络   通信   android   服务器   

/**
 * 用于建立于服务器之间通信的工具
 * 
 *
 * 
 */
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

标签:网络   通信   android   服务器   

原文地址:http://blog.csdn.net/u014600432/article/details/41522073

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!