java http get请求传json对象

原文章地址,这里只用于记录

DefaultAsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();

Map params = new HashMap<>();
params.put("deviceId","11111111111111");
params.put("devName",eventInfo.getIotName());

Request r = new RequestBuilder()
         .setUrl("http://***.***.***.**:****/gateway")
         .setBody(JSONObject.toJSONString(params))
         .addHeader("Content-Type", "application/json")
         .build();
ListenableFuture future = asyncHttpClient.executeRequest(r);

try {
      Response response = future.get();
} catch (Exception e) {
      e.printStackTrace();
} finally {
      asyncHttpClient.close();
}

你可能感兴趣的:(springboot,java,http,json)