HttpClient与servlet进行通信两种方法
2012-04-19 11:16
411 查看
private static void upload(String url) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); try { ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); list.add(new BasicNameValuePair("name", "我是一只小小鸟!!!!")); HttpEntity en = new UrlEncodedFormEntity(list, HTTP.UTF_8); post.setEntity(en); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Log.e("HttpStatus", "成功!"); String s = EntityUtils.toString(response.getEntity()); Log.e("", "" + s); } else { Log.e("HttpStatus", "失败!"); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static void upload2(String url) { HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost post = new HttpPost(url); try { StringEntity entity = new StringEntity("name=我是一只大大鸟", "UTF-8"); entity.setContentType("application/x-www-form-urlencoded"); post.setEntity(entity); client.execute(post); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
相关文章推荐
- 客户端和应用服务器之间利用HttpClient和Servlet交互JSON对象进行通信
- Android网络连接的两种方法:apache client和httpurlconnection的比较
- 获取网上数据的两种方法HttpURLConnection和HttpClient
- Android网络连接的两种方法:apache client和httpurlconnection的比较
- Ajax获取XmlHttpRequest对象的方法,兼容IE、火狐。用来与服务器进行通信。
- SpringMVC上传图片总结(1)---常规方法进行图片上传,使用了MultipartFile、MultipartHttpServletRequest
- SpringMVC上传图片总结(1)---常规方法进行图片上传,使用了MultipartFile、MultipartHttpServletRequest
- Android HttpClient和URLConnection两种下载HTML源码的方法
- Java中通过方法创建一个http连接并请求(服务器间进行通信)
- Android 实现http通信(servlet做服务器端) HttpClient、HttpURLConnection实现登录验证
- SpringMVC上传图片总结(1)---常规方法进行图片上传,使用了MultipartFile、MultipartHttpServletRequest
- HttpClient Post请求两种方法。
- Android HttpClient和URLConnection两种下载HTML源码的方法
- java网络通信(一)使用http的get方法进行网络通信
- SpringMVC上传图片总结(1)---常规方法进行图片上传,使用了MultipartFile、MultipartHttpServletRequest
- SpringMVC上传图片总结(1)-Web Uploader--常规方法进行图片上传,使用了MultipartFile、MultipartHttpServletRequest
- 利用HttpServletRequestWrapper对HttpServletRequest进行封装的方法
- Android两种HTTP通信,HttpURLConnection和HttpClient
- Android网络连接的两种方法:apache client和httpurlconnection的比较 分类: H1_ANDROID 2013-10-13 23:23 640人阅读 评论(0) 收藏
- Android HttpClient(Get,Post方式)进行网络通信