/**
*需要Internet权限
*/
Apache Post方式发送数据
1、构建URL
URL url=new URL("RemoteURL");
2、建立Http post请求方式
HttpPost httpPost=new HttpPost(url);
3、建立追加请求体
List<NameValuePair> list=new ArrayList<NameValuePair>();
NameValuePair nv=new BaseNameValuePair(key,value);
list.add(nv);
追加请求实体
httpPost.setEntity(list);
4、构建Http客户端
HttpClient client=new DefaultHttpClient();
5、执行请求并返回response
HttpResponse response=client.execute(httpPost);
数据状态判断提示
response.getStatus.getStatus
HttpStatus.SC_OK//成功 状态 一般请求后要判断各种请求状态
Apache Get方式发送数据(Get方式编码问题)
请求参数追加到URL上
构建HttpGet请求方式
建立client
执行HttpGet请求并且返回response
获取repose实体getEtity();然后使用实体辅助类进行解析(EtityUtils)
Apache实体辅助类
URLRecoder
EtityUtils
原始方式建立连接
1、构建URL
2、url.OpenConnection打开连接 返回Connection
3、connection获取响应的输入流inputStream
4、流处理 包装流
InputStreamReader BufferReader(缓冲流提交速率)
*BitMap使用返回的的inputStream流进行二进制图片解析
BitMap bitmapImg=BitMapFactory.decodeStream(inputstream);
Android网络访问请求方式
最新推荐文章于 2022-05-11 20:02:24 发布