您的位置:首页 > 理论基础 > 计算机网络

Android中间httpclient发送帧get求

2015-10-14 15:28 741 查看
/**
* 採用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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: