Android中使用HttpGet和HttpPost访问HTTP资源(二)

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);//参数拼接为完整地址



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值