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

HttpClient发送Get请求(java)【从新浪云搬运】

2016-03-30 21:02 621 查看
直接上代码吧

public static void sendHttpGet(final String url){
//发送Get请求的方法,url中已经带了需要的参数。
new Thread(new Runnable() {

@Override
public void run() {
HttpGet getMethod = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = httpClient.execute(getMethod); //发起GET请求
Log.i("HTQ", "resCode = " + response.getStatusLine()
.getStatusCode()); //获取响应码
Log.i("HTQ", "result = " + EntityUtils
.toString(response.getEntity(), "utf-8"));//获取服务器响应内容
} catch (Exception e){
e.printStackTrace();
}

}
}).start();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: