首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android经过 HttpClient 请求服务器端例子

2013-12-15 
android通过 HttpClient 请求服务器端例子? ? ? // http地址 ?? ? ? ? String httpUrl http://192.168.

android通过 HttpClient 请求服务器端例子

? ? ? // http地址 ?

? ? ? ? String httpUrl = "http://192.168.1.110:8080/my.jsp?method=testGet"; ?

? ? ? ? //HttpGet连接对象 ?

? ? ? ? HttpGet httpRequest = new HttpGet(httpUrl); ?

? ? ? ? ?//取得HttpClient对象 ?

? ? ? ? ? ? HttpClient httpclient = new DefaultHttpClient(); ?

? ? ? ? ? ? //请求HttpClient,取得HttpResponse ?

? ? ? ? ? ? HttpResponse httpResponse = httpclient.execute(httpRequest); ?

? ? ? ? ? ? //请求成功 ?

? ? ? ? ? ? if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) ?

? ? ? ? ? ? { ?

? ? ? ? ? ? ? ? //取得返回的字符串 ?

? ? ? ? ? ? ? ? String strResult = EntityUtils.toString(httpResponse.getEntity()); ?

? ? ? ? ? ? ? ?//strResult ?

? ? ? ? ? ? } ?

? ? ? ? ? ? else?

? ? ? ? ? ? { ?

? ? ? ? ? ? ? ?//请求失败

? ? ? ? ? ? } ?

? ? ? ? }?

1 楼 酷的飞上天空 4 小时前   请求完成后注意释放HttpClient建立的链接

热点排行