Android入门:HttpClient介绍
2014-12-05 14:41
459 查看
一、HttpClient介绍 HttpClient是用来模拟HTTP请求的,其实实质就是把HTTP请求模拟后发给Web服务器; Android已经集成了HttpClient,因此可以直接使用; 注:此处HttpClient代码不只可以适用于Android,也可适用于一般的Java程序; HTTP GET核心代码: (1)DefaultHttpClient client = new DefaultHttpClient(); (2)HttpGet get = new HttpGet(String url);//此处的URL为http://..../path?arg1=value&....argn=value (3)HttpResponse response = client.execute(get); //模拟请求 (4)int code = response.getStatusLine().getStatusCode();//返回响应码 (5)InputStream in = response.getEntity().getContent();//服务器返回的数据 HTTP POST核心代码: (1)DefaultHttpClient client = new DefaultHttpClient(); (2)BasicNameValuePair pair = new BasicNameValuePair(String name,String value);//创建一个请求头的字段,比如content-type,text/plain (3)UrlEncodedFormEntity entity = new UrlEncodedFormEntity(List<NameValuePair> list,String encoding);//对自定义请求头进行URL编码 (4)HttpPost post = new HttpPost(String url);//此处的URL为http://..../path (5)post.setEntity(entity); (6)HttpResponse response = client.execute(post); (7)int code = response.getStatusLine().getStatusCode(); (8)InputStream in = response.getEntity().getContent();//服务器返回的数据
相关文章推荐
- android-async-http AsyncHttpClient介绍
- Android基础入门教程——7.1.4 Android HTTP请求方式-HttpClient
- (HttpClient技术)(HttpClient入门)HttpClient使用详细介绍
- Android HttpClient HttpURLConnection相关介绍
- 07_android入门_採用HttpClient的POST方式、GET方式分别实现登陆案例
- android-async-http AsyncHttpClient介绍
- Android两种网络访问方式(HttpClient HttpUrlConnection)的比较及三种传参方式介绍
- android-async-http AsyncHttpClient介绍
- Java4Android之HttpClient入门使用代码集
- android-async-http AsyncHttpClient介绍
- android-async-http AsyncHttpClient介绍
- 08_android入门_android-async-http开源项目介绍及用法
- Android-async-http AsyncHttpClient介绍
- android-async-http AsyncHttpClient介绍
- android-async-http AsyncHttpClient介绍
- android-async-http AsyncHttpClient介绍
- Android入门笔记 - 网络通信 - HttpClient
- Android入门(二十)HttpURLConnection与HttpClient
- 08_android入门_android-async-http开源项目介绍及使用方法
- android httpclient 上传文件