try { // 编码请求参数 String getHttpParam = http_build_query(parameters); String fullUrl = url + "key=" + keyStr + "&" + getHttpParam; LOGGER.info("sync user url:"+fullUrl); OkHttpClient client = new OkHttpClient();//创建OkHttpClient对象 Request request = new Request.Builder() .url(fullUrl)//请求接口。如果需要传参拼接到接口后面。 .build();//创建Request 对象 Response response = null; response = client.newCall(request).execute();//得到Response 对象 if (response.isSuccessful()) { String resultStr = response.body().string(); if (StringUtils.isEmpty(resultStr)){return null;} loginUserVO = JsonMapper.nonNullMapper().fromJson(resultStr, SingleLoginVO.class); LOGGER.info("获取单点登录用户信息成功!用户名称 {},用户id {}。", loginUserVO.getName(), loginUserVO.getId()); } } catch (Exception e) { LOGGER.error("获取单点登录用户信息异常:", e); }
OkHttp简单用法!
最新推荐文章于 2020-12-25 01:15:08 发布