Android中的httpclient框架发送get请求

/**
	 * 採用httpclientGet请求的方式
	 * 
	 * @param username
	 * @param password
	 * @return null表示求得的路径有问题,text返回请求得到的数据
	 */
	public static String httpclientGet(String username, String password) {
		try {
			// 1.打开一个浏览器
			HttpClient client = new DefaultHttpClient();
			// 2.输入地址
			String path = "http://172.22.64.156:8080/0001AndroidWebService/LoginServlet?username="
					+ URLEncoder.encode(username)
					+ "&password="
					+ URLEncoder.encode(password);
			// 指定请求方式
			HttpGet get = new HttpGet(path);
			// 3.敲回车
			HttpResponse response = client.execute(get);
			//获取返回的码
			int code = response.getStatusLine().getStatusCode();
			if (code == 200) {
				//获取返回的信息
				InputStream is = response.getEntity().getContent();
				String text = StreamUtil.readStream(is);
				return text;
			} else {
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

原文地址:https://www.cnblogs.com/llguanli/p/6755074.html