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

Httplient  获取网络数据

2014-05-15 22:55 106 查看
get: HttpClient http = new DefaultHttpClient();

     HttpGet httpGet = new HttpGet(url);

 

     HttpResponse response = http.execute(httpGet);

      

     InputStream in = response.getEntity().getContent();

post: HttpClient client = new DefaultHttpClient();

      HttpPost post = new HttpPost(url);

      // 设置参数 

      List  params = new ArrayList();

      BasicNameValuePair  val = new BasicNameValuePair("selected", String.valueOf(1));

      params.add(val);

      post.setEntity(new UrlEncodedFormEntity(params, "utf-8"));

      HttpResponse response = client.execute(post);

      HttpEntity entity = response.getEntity();

      InputStream in = entity.getContent();

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