• Http发送Json


     1     public static JSONObject post(String url,JSONObject json){  
     2             HttpClient client = new DefaultHttpClient();  
     3             HttpPost post = new HttpPost(url);  
     4             JSONObject response = null;  
     5             try {  
     6                 StringEntity s = new StringEntity(json.toString(),"UTF-8");  //服务器返回中文乱码,加上"UTF-8"可以了
     7                 s.setContentEncoding("UTF-8");  
     8                 s.setContentType("application/json");  
     9                 post.setEntity(s);  
    10                   
    11                 HttpResponse res = client.execute(post);  
    12                 if(res.getStatusLine().getStatusCode() == HttpStatus.OK.value()){  
    13                     HttpEntity entity = res.getEntity();  
    14                     String charset = EntityUtils.getContentCharSet(entity);  
    15                     response = new JSONObject(new JSONTokener(new InputStreamReader(entity.getContent(),charset)));  
    16                 }  
    17             } catch (Exception e) {  
    18                 throw new RuntimeException(e);  
    19             }  
    20             return response;  
    21         }  

    http://201202104504.iteye.com/blog/1413714

  • 相关阅读:
    RSA使用
    C#获取主机信息
    NSIS打包软件使用
    C#获取局域网主机
    C#实现Web链接启动应用程序
    4.布局介绍
    Server Sql 多表查询、子查询和分页
    C# File类常用方法
    Vue 使用技巧手记
    前端面试题手记
  • 原文地址:https://www.cnblogs.com/hym-pcitc/p/5674324.html
Copyright © 2020-2023  润新知