在一个方法里面去请求第三方的接口

现在做的是需要对接一个硬件厂商提供的接口,第一次请求别人的接口,不是很会

 HttpResponse execute = HttpRequest.post("/api/eventService/v1/eventSubscriptionByEventTypes").body(toJsonStr).execute();
        String body = execute.body();
        Map<String, String> response = JSONUtil.toBean(body, Map.class);
        return response;

通过httprequest发起post请求:HttpRequest.post,里面的是接口地址
.body(toJsonStr).execute();是把toJsonStr这个参数放到请求体中,最后再执行请求,得到的execute是一个HttpRequest对象,将它转为一个map对象并返回

猜你喜欢

转载自blog.csdn.net/weixin_42260782/article/details/109847132
今日推荐