当前位置: 代码迷 >> Android >> android 联接服务器
  详细解决方案

android 联接服务器

热度:87   发布时间:2016-05-01 12:59:35.0
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; }}

??

  相关解决方案