import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import org.apache.http.HttpEntity;
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; public class TTT
{ /**
* @param args
* @throws IOException
* @throws ClientProtocolException
*/
public static void main(String[] args) throws ClientProtocolException, IOException
{
// 创建HttpClient实例
HttpClient httpclient = new DefaultHttpClient();
// 创建Get方法实例
HttpGet httpgets = new HttpGet("http://127.0.0.1/testhttp.php?username=yonghuming");
HttpResponse response = httpclient.execute(httpgets);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
String str = convertStreamToString(instreams);
System.out.println("Do something");
System.out.println(str);
// Do not need the rest
httpgets.abort();
}
} public static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder(); String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
} }

最新文章

  1. IOS 页面之间的跳转
  2. c语言编程之双向循环链表
  3. Careercup - Google面试题 - 6407924087783424
  4. 原 Debian设置开机自动启动与关闭
  5. 实时错误 '91' :对象变量或with块变量未设置
  6. 在Fedora 23 Server和Workstation上安装LAMP(Linux, Apache, MariaDB和PHP)
  7. 四轴飞行器1.3 MPU6050(大端)和M4的FPU开启方法
  8. iOS 推送全解析,你不可不知的所有 Tips!
  9. js 四舍五入函数 toFixed(),里面的参数 就是保留小数的位数。
  10. 详解Java中的clone方法
  11. permission denied for window type 2003
  12. offsetLeft 解析
  13. 【原创】大叔经验分享(8)创建hive表时用内部表还是外部表
  14. dpkg: 处理软件包 qjackctl (--configure)时出错解决方法
  15. Linux-程序包管理
  16. 解题:SDOI 2017 硬币游戏
  17. Linux内存管理学习2 —— head.S中的段页表的建立
  18. 2018房地产沉思录 z
  19. scala "←" "<-"
  20. 高阶篇:4.2.3)DFMEA现有设计:预防控制与探测控制

热门文章

  1. nginx json 格式输出
  2. Velocity模板引擎语法
  3. 如何快速建立一个测试资源Web服务器及异步获取资源(Unity3D)
  4. 日常开发使用SVN命令
  5. javascript的语法结构
  6. Hibernate Criteria Restrictions
  7. ubuntu 在mac 的 Parallels 的分辨率问题
  8. 精通AngularJS 读书笔记(1)
  9. python中的正则表达式(re模块)
  10. Android中Bitmap和Drawable