用gradle构建的项目进行接口的外部访问

//url和token参数自己定义即可
mLog.debug(“获取配置的url数据: " + url);
mLog.debug(”>>>>>>>>> TokenServer getToken");
OkHttpClient client =
moaHttpClientFactory.getInstance().newBuilder().addNetworkInterceptor(new LoggingInterceptor()).build();
mLog.debug(“------进入请求地址:”+url + “?token=” + tokens);
//这边由于没啥参数就给他设置null的
RequestBody body = RequestBody.create(null, new byte[0]);
Request request = new Request.Builder().method(“POST”, body)
.url(url + “?token=” + tokens)
.build();
mLog.debug(“完成…”);
try (Response response = client.newCall(request).execute()) {
mLog.debug(“TokenServer getToken response: " + response);
mLog.debug(“TokenServer getToken response: " + response.isSuccessful());
String content = IOUtils.toString(response.body().byteStream(), StandardCharsets.UTF_8);
mLog.debug(”>>>>>>>>> TokenServer getToken content”);
mLog.debug(content);
//这边content的值已经变成了String类型,里面的格式是json直接转换就行,后面就是我需求需要获取某一参数的步骤
mLog.debug(“>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>”);
Map resultMap = (Map) objectMapper.readValue(content, Map.class).get(“data”);
mLog.debug(“获取uid为:”+resultMap.get(“uid”));
String uid = (String) resultMap.get(“uid”);
mLog.debug(“返回uid为:”+uid);
return uid;

你可能感兴趣的:(android,java,开发语言)