一,在后台程序中发送http请求获取响应数据
1)以 http://libs.baidu.com/jquery/2.0.0/jquery.min.js 为例
二,
1)
String result=""; ???????BufferedReader in = null; ???????URL url = null; ???????try { ???????????url = new URL("http://libs.baidu.com/jquery/2.0.0/jquery.min.js"); ???????} catch (MalformedURLException e) { ???????????e.printStackTrace(); ???????} ???????//打开连接 ???????URLConnection connection = url.openConnection(); ???????????????// 设置通用的请求属性 ???????connection.setRequestProperty("accept", "*/*"); ???????connection.setRequestProperty("connection", "Keep-Alive"); ???????connection.setRequestProperty("user-agent", ???????????????"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); ???????// 建立实际的连接 ???????connection.connect(); ???????????????// 定义 BufferedReader输入流来读取URL的响应 ???????in = new BufferedReader(new InputStreamReader( ???????????????connection.getInputStream())); ???????//写出数据 ???????String line; ???????while ((line = in.readLine()) != null) { ???????????result += line; ???????} ???????//关流 ???????in.close(); ???????System.out.println(result);
三,
在后台程序中发送http请求并获取响应数据
原文地址:http://www.cnblogs.com/hi-feng/p/8006750.html