`
estn_h
  • 浏览: 14458 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

HttpClient发送get请求

阅读更多

 

HttpClient httpClient = new DefaultHttpClient();
		HttpGet httpGet = new HttpGet(url);
		HttpResponse httpResponse = httpClient.execute(httpGet);
		HttpEntity entity = httpResponse.getEntity();

		if (entity != null) {
			InputStream inStream = entity.getContent();
			// 从流中读取数据
			try {
				BufferedReader in = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
				String result = in.readLine();
				System.out.println(result);
			} finally {
				try {
					if (inStream != null) {
						inStream.close();
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} else {
			System.out.println("error");
		} //end of if
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics