下面是对apche方式的网络请求进行的一个简单封装
主要用到的类:
HttpClient client = new DefaultHttpClient();
HttpGet/HttpPost---父类 HttpUriRequest
HttpResponse
工具类EntityUtils.toString(response.getEntity);获取服务器响应内容
post传数据:
BasicNameValuePair
HttpEntity entity = new UrlEncodeFormEntity(List<BasicNameValuePair>);
request.setEntity(entity,encodecharset);
使用:
不传参数:
new HttpConnectUtil().httpConnectByApache(Method.GET|Method.POST, String httpUrl,
new HttpConnectionResponse(){
<span style="font-size:18px;">public void handleHttpResponse(String response)<span style="font-size:18px;">{</span></span>