HttpURLConnection请求
来源:互联网 发布:淘宝发货没有无需物流 编辑:程序博客网 时间:2024/05/16 02:18
// HttpURLCONnection+Thread+handler
new Thread(){
public void run() {
try {
URL url=new URL(path);
//HttpURLCONnection get请求数据
HttpURLConnection openConnection = (HttpURLConnection) url.openConnection();
openConnection.setReadTimeout(5000);
openConnection.setConnectTimeout(5000);
openConnection.setRequestMethod("GET");
openConnection.connect(); //连接
int responseCode = openConnection.getResponseCode();
if(responseCode==200){
InputStream inputStream = openConnection.getInputStream();
String json = streamTo(inputStream);
Message msg=Message.obtain();
msg.what=1;
msg.obj=json;
handler.sendMessage(msg);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
//输入流
public String streamTo(InputStream input){
ByteArrayOutputStream baos=new ByteArrayOutputStream();
byte[] by=new byte[1024];
int len=0;
try {
while((len=input.read(by))!=-1){
baos.write(by, 0, len);
}
System.out.println("streamto=="+baos.toString());
return baos.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
0 0
- HttpURLConnection请求
- HttpURLConnection请求
- HttpURLConnection请求
- HttpURLConnection 请求
- HttpUrlConnection请求
- HttpURLConnection请求服务
- HttpURLConnection post 请求
- HttpURLConnection请求图片
- HttpURLConnection post请求
- 请求网络之HttpUrlConnection
- HttpURLConnection数据请求
- HttpUrlconnection get请求数据
- Android HttpURLConnection post请求
- httpUrlConnection请求数据
- HttpURLConnection 的get请求
- HttpURLConnection请求数据
- HttpURLConnection请求网络
- HttpURLConnection请求数据
- HtmlUnit解析动态网页并采集网页列表到Excel
- win7 64位下安装ubtuntu双系统,默认windows7系统
- SoftReference
- Jenkins + SVN + Batch Command (项目的自动打包和部署)
- 关于(UITableViewcell)contentView高度的问题
- HttpURLConnection请求
- 发布IOS产品被拒后如何再上传新发布包
- Xshell -- 中文乱码问题
- ios开发网络篇—NSURLConnection基本使用
- 侧滑
- Javascript this关键字
- 给分类设置Meta Keywords
- 转载:对大学 IT 专业教育的反馈
- 无限轮播