首页 > 移动平台 > 详细

bsh for android : URL Connect Test

时间:2014-04-05 16:05:38      阅读:539      评论:0      收藏:0      [点我收藏+]

beanshell : URLConnectTest.bsh

source("/sdcard/com.googlecode.bshforandroid/extras/bsh/android.bsh");
a = Android();

urlName = a.call("dialogGetInput","Connect Test","Input URL:").get("result");
print(urlName);
try {
	URL url = new URL("http://"+ urlName);
	URLConnection conn = url.openConnection();
	conn.connect();
	Scanner in = new Scanner(conn.getInputStream());
	Map headers = conn.getHeaderFields();
	for (Map.Entry entry : headers.entrySet()){
		String key = entry.getKey();
		for (String value : entry.getValue())
			print(key +": "+ value);
	}
	for (int n=1; in.hasNextLine() && n <=5; n++)
		print(in.nextLine());
	if (in.hasNextLine()) print("...");

} catch(e){
	print(e);
}

参考: Core Java 2 Volume II ( 7th Edition)  v2ch3

bsh for android : URL Connect Test,布布扣,bubuko.com

bsh for android : URL Connect Test

原文:http://blog.csdn.net/belldeep/article/details/22961481

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!