spring 中的Http + json 的post请求方式

//请求模拟

    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httpPost = new HttpPost("http://134.64.115.20:9999/datanet/queryCircuitInfo");

    httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");

    JSONObject request = new JSONObject();

    request.element("domain", "");

    request.element("ipAddress", "");

    request.element("pageIndex", "1");

    request.element("pageSize", "100");

    System.out.println("===" + request.toString());

    log.info("入参==" + request.toString());

    String returnJsonStr = null;

    try {

      httpPost.setEntity(new StringEntity(request.toString(), "UTF-8"));

      HttpResponse response = httpclient.execute(httpPost);

      HttpEntity entity = response.getEntity();

      returnJsonStr = EntityUtils.toString(entity, "UTF-8");

      System.out.println("返回JSON数据为:" + returnJsonStr);

      log.info("出参==" + returnJsonStr);

    } catch (Exception ex) {

      ex.printStackTrace();

    }

//spring 模拟接收

        @ResponseBody

@RequestMapping(value="/queryDataInfo",method=RequestMethod.POST,consumes="application/json",produces="application/json")

public PageResult<DataNetCircuitBo> queryDataInfo(@RequestBody ParamBo paramBo){

        }


你可能感兴趣的:(spring 中的Http + json 的post请求方式)