当前位置: 代码迷 >> Android >> 采取Android中的httpclient框架发送get请求
  详细解决方案

采取Android中的httpclient框架发送get请求

热度:60   发布时间:2016-04-28 05:25:26.0
采用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;		}	}

2楼yaoshilu1463天前 21:36
1
1楼yaoshilu1463天前 21:35
222222222
  相关解决方案