HttpClient访问网络
2014-09-28 16:51
337 查看
HttpClient项目时Apache提供用于访问网络的类,对访问网络的方法进行了封装。在HttpURlConnection类中的输入输出操作,统一封装成HttpGet、HttpPost、HttpResponse
一、服务器端前台
1、发送GET请求的步骤:
(1)创建HttpClient对象:HttpClient httpClient=new DefaultHttpClient();
(2)创建HttpGet对象:HttpGet httpGet=new HttpGet("http://www.teachcourse.cn");
(3)添加发送参数:httpGet.setParams("姑娘的眼睛真大,好漂亮咯!");
(4)调用HttpClient对象的execute()方法发送请求:HttpResponse httpResponse=httpClient.execute();
2、案例演示:
一、服务器端前台
1、发送GET请求的步骤:
(1)创建HttpClient对象:HttpClient httpClient=new DefaultHttpClient();
(2)创建HttpGet对象:HttpGet httpGet=new HttpGet("http://www.teachcourse.cn");
(3)添加发送参数:httpGet.setParams("姑娘的眼睛真大,好漂亮咯!");
(4)调用HttpClient对象的execute()方法发送请求:HttpResponse httpResponse=httpClient.execute();
2、案例演示:
HttpClient httpClient=new DefaultHttpClient(); HttpGet httpGet=new HttpGet("http://www.teachcourse.cn"); try{ HttpResponse httpResponse=httpClient.execute(); if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK){//解释服务器响应 result=EntityUtils.toString(httpResponse.getEntiry());//获取返回的字符串 }else{result="请求失败!";} }catch(ClientProtocolException e){ e.printStackTrace(); }catch(IOException e){e.printStackTrace();};
相关文章推荐
- 简单使用URLConnection、HttpURLConnection和HttpClient访问网络资源
- Android访问网络,使用HttpURLConnection还是HttpClient?
- Android访问网络,使用HttpURLConnection还是HttpClient?
- 网络访问httpconnection httpclient 文件传输
- Android访问网络,使用HttpURLConnection还是HttpClient?
- 简单使用URLConnection、HttpURLConnection和HttpClient访问网络资源
- Android访问网络,使用HttpURLConnection还是HttpClient?
- Android访问网络,使用HttpURLConnection还是HttpClient?
- Android访问网络,使用HttpURLConnection还是HttpClient?
- Httpclient通过代理访问网络
- Android访问网络,使用HttpURLConnection还是HttpClient?
- Android访问网络,使用HttpURLConnection还是HttpClient?
- Android访问网络,使用HttpURLConnection还是HttpClient?
- Android访问网络,使用HttpURLConnection还是HttpClient?
- android通过 httpClient 的post访问 网络数据
- crawler_基础之_httpclient 访问网络资源
- cocos2d-x CCHttpClient 访问网络
- Android访问网络,HttpURLConnection还是HttpClient?
- android HttpClient访问网络获取数据
- Android访问网络,使用HttpURLConnection还是HttpClient?