zoukankan      html  css  js  c++  java
  • Android HttpClient POST JSON Restful-web-services

    @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;
            }
  • 相关阅读:
    前端UI框架
    Knowledge
    Microsoft SQL Server
    ASP.NET MVC
    将博客搬至CSDN
    python中的数据类型
    python基础知识
    接口和抽象类的区别
    面向对象的四大特征
    数据结构学习笔记
  • 原文地址:https://www.cnblogs.com/yshyee/p/4730688.html
Copyright © 2011-2022 走看看