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

你可能感兴趣的:(httpclient)