android http 通信(httpclient 实现)

1.httpclient get 方式

  HttpGet httpGet = new HttpGet(url);
  HttpClient client = new DefaultHttpClient();
  HttpResponse response=client.execute(httpGet);
  if(response.getStatusLine().getStatusCode() == HttpStatus.SC_Ok){
    String content = EntityUtils.toString(response.getEntity);
  }

2.httpclient post 方式

HttpPost post= new HttpPost(url);
HttpClient client = new DefaultHttpClient(); ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("name",name));
list.add(new BasicNameValuePair("age",age)); post.setEntity(new UrlEncodedFormEntity(list)); HttpResponse response=client.execute(post);
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_Ok){
 String content = EntityUtils.toString(response.getEntity);
}
上一篇:Firbird 将可 null 的列更新为 not null


下一篇:hibernate的批量更新、批量删除