android http 通信(httpclient 实现)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); }
以上是关于android http 通信(httpclient 实现)的主要内容,如果未能解决你的问题,请参考以下文章
HttpClien高并发请求连接池 - PoolingHttpClientConnectionManager
Android实战之旅 006Android中的HTTP通信
使用 JAVA/Android 和 Http 的 Chromecast 通信