Android中使用HttpGet和HttpPost访问HTTP资源(二)
2014-02-08 15:25
567 查看
File file = new File("somefile.txt");
FileEntity entity = new FileEntity(file, "text/plain; charset=\"UTF-8\"");
HttpPost httppost = new HttpPost("http://localhost/action.do");
httppost.setEntity(entity);//各种Entity之FileEntity
List<NameValuePair>list=new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("name", name));
list.add(new BasicNameValuePair("pwd", pwd));
httpPost.setEntity(new UrlEncodedFormEntity(list,HTTP.UTF_8));//各种Entity之UrlEncodedFormEntity
MultipartEntity mpEntity = new MultipartEntity();
File file = new File(fileurl);
mpEntity.addPart("file", newFileBody(file));//可用于自制文件的上传
mpEntity.addPart("data", new StringBody(data, Charset.forName(org.apache.http.protocol.HTTP.UTF_8)));
httpPost.setEntity(mpEntity);//各种Entity之MultipartEntity
----------------------------------------------
httpPost = new HttpPost(url);
......
HttpResponse response = client.execute(httpPost);//参数为完整地址
host = new HttpHost(domain, 80, "http");
httpPost = new HttpPost(url);
......
response = client.execute(host, httpPost);//参数拼接为完整地址
FileEntity entity = new FileEntity(file, "text/plain; charset=\"UTF-8\"");
HttpPost httppost = new HttpPost("http://localhost/action.do");
httppost.setEntity(entity);//各种Entity之FileEntity
List<NameValuePair>list=new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("name", name));
list.add(new BasicNameValuePair("pwd", pwd));
httpPost.setEntity(new UrlEncodedFormEntity(list,HTTP.UTF_8));//各种Entity之UrlEncodedFormEntity
MultipartEntity mpEntity = new MultipartEntity();
File file = new File(fileurl);
mpEntity.addPart("file", newFileBody(file));//可用于自制文件的上传
mpEntity.addPart("data", new StringBody(data, Charset.forName(org.apache.http.protocol.HTTP.UTF_8)));
httpPost.setEntity(mpEntity);//各种Entity之MultipartEntity
----------------------------------------------
httpPost = new HttpPost(url);
......
HttpResponse response = client.execute(httpPost);//参数为完整地址
host = new HttpHost(domain, 80, "http");
httpPost = new HttpPost(url);
......
response = client.execute(host, httpPost);//参数拼接为完整地址
相关文章推荐
- Android中使用HttpGet和HttpPost访问HTTP资源和区别
- Android中使用HttpGet和HttpPost访问HTTP资源(一)
- Android中使用HttpGet和HttpPost访问HTTP资源
- 使用HTTP GET 和HTTP POST请求访问HTTP资源
- android 使用httpget访问并获取http资源(httpget的使用)
- android 使用http get 与post 访问网络
- 使用HTTP GET 和HTTP POST请求访问HTTP资源
- android 使用http get 与post 访问网络
- Android中使用HttpGet和HttpPost访问HTTP资源
- Android中使用HttpURLConnection和HttpClient实现GET和POST请求访问网络
- Android-HTTP实例——使用GET方法、POST方法发送请求(安卓4.0以下版本)
- android 网络编程 HttpGet和HttpPost类使用详解
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- android中HTTP协议访问网络及其方式及其http的GET和POST的优缺点
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求(通过Apache接口实现)
- android_30_使用HttpClient发送Get和Post请求
- Android使用HTTP GET、HTTP POST获取网络数据
- android 网络编程 HttpGet和HttpPost类使用详解
- Android HTTP实例 使用GET方法和POST方法发送请求