码迷,mamicode.com
首页 > 移动开发 > 详细

Android HttpClient POST JSON Restful-web-services

时间:2015-08-14 18:52:05      阅读:123      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!