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

android 联接服务器

2012-11-12 
android 连接服务器public class JsonUtil {public static String jsonpublic static String findAll(Str

android 连接服务器

public class JsonUtil {public static String json;public static String findAll(String strUrl) throws Exception {  // 创建请求HttpClient客户端  System.out.println("连接上服务器");  HttpClient httpClient = new DefaultHttpClient();  // 创建请求的url  // 创建请求的对象  HttpGet get = new HttpGet(new URI(strUrl));  // 发送get请求  HttpResponse httpResponse = httpClient.execute(get);  // 如果服务成功返回响应  if (httpResponse.getStatusLine().getStatusCode() == 200) {   HttpEntity entity = httpResponse.getEntity();   if (entity != null) {    // 获取服务器响应的json字符串   json = EntityUtils.toString(entity, "UTF-8");    System.out.println(json);     //输出返回的字符串信息   }  } else {   System.out.println("连接超时");  }  return json; }}

??

热点排行