HTTP的应用httpclient 和线程
package com.example.service; import java.io.IOException;
import java.io.InputStream; import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.widget.ImageView; public class MainActivity extends Activity { static ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image=(ImageView) findViewById(R.id.image);
/* Intent intent=new Intent(this, MyService.class);
startService(intent);*/ new thrad().start(); }
Handler handle=new Handler(){ @Override
public void handleMessage(Message msg) { image.setImageBitmap((Bitmap) msg.obj);
} };
class thrad extends Thread{ @Override
public void run() {
HttpClient http=new DefaultHttpClient();
HttpGet request=new HttpGet("http://dh2.kimg.cn/www/meinv/5/7f/547f54c2a9712b8b2e7be7a5ca2fe5fd-af35e4");
HttpResponse response = null;
try {
response = http.execute(request);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream in = null;
try {
in = response.getEntity().getContent();
//String str=EntityUtils.toString(response.getEntity());
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//服务器返回的数据
Bitmap bitmap=BitmapFactory.decodeStream(in);
Message msg=handle.obtainMessage();
msg.obj=bitmap;
handle.sendMessage(msg);
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
}
HTTP的应用httpclient 和线程的更多相关文章
- httpclient模拟浏览器get\post
一般的情况下我们都是使用IE或者Navigator浏览器来访问一个WEB服务器,用来浏览页面查看信息或者提交一些数据等等.所访问的这些页面有的仅 仅是一些普通的页面,有的需要用户登录后方可使用,或者需 ...
- HttpClient 4.3教程(转载)
HttpClient 4.3教程(转载) 转自:http://www.yeetrack.com/?p=779 前言 Http协议应该是互联网中最重要的协议.持续增长的web服务.可联网的家用电器等都在 ...
- httpclient总结
1.httpclient总结:一.基本知识准备(1)构建URI工具类,URIBuilder(2)HttpResponse类,可以添加Header信息 获取所有Header信息的方法,调用HeaderI ...
- HttpClient学习记录-系列1(tutorial)
1. HttpClient使用了facade模式,如何使用的? 2. HTTP protocol interceptors使用了Decorator模式,如何使用的? URIBuilder respon ...
- httpclient的并发连接问题
昨天的搜索系统又出状况了,几个库同时重建索引变得死慢.经过一个上午的复现分析,确定问题出现httpclient的使用上(我使用的是3.1这个被广泛使用的遗留版本).搜索系统在重建索引时,是并发多个线程 ...
- 【工具】- HttpClient篇
简介 对于httpclient,相信很多人或多或少接触过,对于httpclient的使用姿势,相信很多人会有疑问?下面这边会通过代码说明 package xxx; import org.apache. ...
- 程序员节应该写博客之.NET下使用HTTP请求的正确姿势
程序员节应该写博客之.NET下使用HTTP请求的正确姿势 一.前言 去年9月份的时候我看到过外国朋友关于.NET Framework下HttpClient缺陷的分析后对HttpClient有了一定的了 ...
- 使用HttpClient4来构建Spring RestTemplate
Spring RestTemplate简单说明 现在REST服务已经很普及了,在我们的程序中,经常会需要调用REST API,这时候会有很多选择,原始一点的JDK自带的,再进一步点使用HttpClie ...
- httpclient4.5 的一些细节
本文转自:http://mercymessi.iteye.com/blog/2250161 httpclient是Apache下的一个用于执行http网络访问的一个工具包. 大致流程:新建一个http ...
随机推荐
- Win10/UWP新特性系列—Launcher实现应用间的通信
UWP中,微软为Windows.System.Launcher启动器新增了很多的功能,以前只能启动App,打开指定扩展名文件,对uri协议的解析,以及当启动的应用没有安装时则会提示前往商店下载等. 如 ...
- LNMP安装一键安装包
系统需求: CentOS/Debian/Ubuntu Linux系统 需要2GB以上硬盘剩余空间 128M以上内存,OpenVZ的建议192MB以上(小内存请勿使用64位系统) VPS或服务器必须已经 ...
- php-访问数据库
建一个连接,造一个连接对象 $db = new MySQLi("host","username","passwd","databa ...
- 网络数据包收发流程(四):协议栈之packet_type
进入函数netif_receive_skb()后,skb正式开始协议栈之旅.先上图,协议栈大致过程如下所示:跟OSI七层模型不同,linux根据包结构对网络进行分层.比如,arp头和ip头都是紧跟在以 ...
- 腾讯优测优分享 | 这些年,我们追过的 fiddler
腾讯优测是专业的移动云测试平台,提供全面兼容性测试,远程真机租用,漏洞分析等多维度的测试服务,旗下优分享提供大量的移动研发及测试相关的干货! 一.fiddler原理简介 fiddler是目前最强大最好 ...
- Linux命令:nohup、df、du与/dev/null
早上开始工作时发现服务器挂掉了,重启TongWeb时有报错: 上面的红框圈错了,第一个红框的下一行: java.io.IOException: No Space left on device 我们用d ...
- 2015GitWebRTC编译实录12
2015.07.20 libjingle_peerconnection 编译通过[1382/1600 ] CXX obj/talk/app /webrtc/libjingle_peerconnecti ...
- kernel/module.c
#include <linux/errno.h>#include <linux/kernel.h>#include <asm/segment.h>#include ...
- springMVC返回json
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> < ...
- LA 3938 动态最大连续和 线段树
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...