zoukankan      html  css  js  c++  java
  • HttpPost发送Json

    1. 1.public static JSONObject post(String url,JSONObject json){    
    2. 2.        HttpClient client = new DefaultHttpClient();    
    3. 3.        HttpPost post = new HttpPost(url);    
    4. 4.        JSONObject response = null;    
    5. 5.        try {    
    6. 6.            StringEntity s = new StringEntity(json.toString());    
    7. 7.            s.setContentEncoding("UTF-8");    
    8. 8.            s.setContentType("application/json");    
    9. 9.            post.setEntity(s);    
    10. 10.                
    11. 11.            HttpResponse res = client.execute(post);    
    12. 12.            if(res.getStatusLine().getStatusCode() == HttpStatus.OK.value()){    
    13. 13.                HttpEntity entity = res.getEntity();    
    14. 14.                String charset = EntityUtils.getContentCharSet(entity);    
    15. 15.                response = new JSONObject(new JSONTokener(new InputStreamReader(entity.getContent(),charset)));    
    16. 16.            }    
    17. 17.        } catch (Exception e) {    
    18. 18.            throw new RuntimeException(e);    
    19. 19.        }    
    20. 20.        return response;    
    21. 21.    }    
  • 相关阅读:
    git npm包管理
    c# 多线程多个参数
    c# 笔试面试题01
    数据笔试题
    SQL重复记录查询的几种方法
    大数据库脚本文件执行
    ef5 数据库操作
    nodejs ejs模板数据库操作
    node jade模板数据库操作
    nodejs 中jead模板改为ejs
  • 原文地址:https://www.cnblogs.com/zey23/p/3974577.html
Copyright © 2011-2022 走看看