首页 > 移动平台 > 详细

Android HttpClient POST JSON Restful-web-services

时间:2015-08-14 18:51:15      阅读:207      评论:0      收藏:0      [点我收藏+]
@Override
        protected String doInBackground(String... arg0) {
            Gson gson = new Gson();
            String json = gson.toJson(map);
            
            HttpPost httpPost = new HttpPost(WR.URL_YJFK);
            
            String result = null;
            
            try {
                StringEntity entity = new StringEntity(json, HTTP.UTF_8);
                
                entity.setContentType("application/json");
                httpPost.setEntity(entity);
                HttpClient client = new DefaultHttpClient();
                HttpResponse response = client.execute(httpPost);
                
                if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
                    InputStream in = response.getEntity().getContent();
                    result = StrUtil.readString(in);
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            return result;
        }

 

Android HttpClient POST JSON Restful-web-services

原文:http://www.cnblogs.com/yshyee/p/4730688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!