
导入jar包
cn.hutool hutool-all5.3.5
http发送请求.
//map中是参数 HashMapmap = new HashMap<>(); //post请求 String post = HttpUtil.post(url, map); //转换JSonObject JSONObject jsonObject = new JSONObject(post); //获取其中一个jsonstring String code = jsonObject.getStr("code"); //获取其中的jsonobject 在获取其中的一条属性 tonken = jsonObject.getJSONObject("obj").getStr("accessToken"); //转换list //elementType : xxx.class //key : 在json中的是list集合的属性名字 List rows = JSONUtil.toList(obj.getJSONArray(key), elementType);
http请求带有请求头
//参数
JSONObject param= new JSONObject();
param.set("code", code);
param.set("page", page);
param.set("size", size);
//请求结果
String result = HttpRequest.get(url)
//请求头中的参数
.header("api-key", tonken)
.form(param)
.execute().body();
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)