zoukankan      html  css  js  c++  java
  • Httpclient发送json请求

    一、Httpclient发送json请求

    public String RequestJsonPost(String url){
        String strresponse = null;
        try{
            HttpClient hc = new DefaultHttpClient();
           HttpPost hp = new HttpPost(url);
           JSONObject jsonParam = new JSONObject();
           jsonParam.put("user","admin");
           jsonParam.put("password", "123456");
           //设置数据为utf-8编码
           StringEntity entity = new StringEntity(jsonParam.toString(),"utf-8");
           //设置请求编码
           entity.setContentEncoding("utf-8");
           //设置请求类型
           entity.setContentType("application/json");
           hp.setEntity(entity);
           //请求并得到结果
           HttpResponse result = hc.execute(hp);
           strresponse = EntityUtils.toString(result.getEntity(),"utf-8").trim();
        }catch(Exception e){
           e.printStackTrace();
    }
    return strresponse;
    }

  • 相关阅读:
    MillerRabin
    BM算法总结
    高斯消元处理自由变元的方法
    [IOI2019]矩形区域
    费用流处理负圈的方法
    回文自动机(PAM)总结
    [TJOI2017]龙舟
    luogu P2252 [SHOI2002]取石子游戏|【模板】威佐夫博弈
    博弈论
    构造
  • 原文地址:https://www.cnblogs.com/beitha/p/6747853.html
Copyright © 2011-2022 走看看