当前位置:网站首页>获取get请求返回值
获取get请求返回值
2022-07-19 14:49:00 【BIG_PEI】
Map<String, Object> map = new HashMap<>(8);
map.put("uid", entity.getUid());
String result = HttpURLConnectionUtil.get(IELTS_URL, map);
JSONObject jsonObject = JSONObject.fromObject(result);
Map<String,Object> map1 = (Map<String, Object>) jsonObject.get("data");
phone = map1.get("phone").toString();
public static String get(String url, Map<String, Object> param) {
StringBuilder builder = new StringBuilder();
try {
StringBuilder params = new StringBuilder();
for (Entry<String, Object> entry : param.entrySet()) {
if (entry.getValue() != null) {
params.append(entry.getKey());
params.append("=");
params.append(entry.getValue().toString());
params.append("&");
}
}
if (params.length() > 0) {
params.deleteCharAt(params.lastIndexOf("&"));
}
URL restServiceURL = new URL(url + (params.length() > 0 ? "?" + params.toString() : ""));
HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();
httpConnection.setRequestMethod("GET");
httpConnection.setRequestProperty("Accept", "application/json");
if (httpConnection.getResponseCode() != 200) {
throw new RuntimeException("HTTP GET Request Failed with Error code : "
+ httpConnection.getResponseCode());
}
InputStream inStrm = httpConnection.getInputStream();
byte[] b = new byte[1024];
int length = -1;
while ((length = inStrm.read(b)) != -1) {
builder.append(new String(b, 0, length));
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}
边栏推荐
- 拥抱资本加速前行,中微半导体已提交IPO辅导备案
- Distance-Based Background Class Regularization for Open-Set Recognition
- 训练自己的实例分割模型
- review第1遍,220619,数据仓库dwb层降维,视频,
- Union and union all operators in SQL
- 220622_preview,知识点10:DWS层搭建--销售主题宽表--step1--字段抽取
- IDEA的Import changes 和enable auto-import
- The top ten domestic open source projects in 2019 are coming fiercely
- idea启动项目很慢
- DWB layer of data warehouse, 220620, HM,
猜你喜欢
2018's pot makes 2019 sad
增强聚合,主题,数据仓库dwb,dws层降维,视频,review第1遍,220620,
How to choose the right LED display screen for stadiums and gymnasiums
10. Thread
MaskTextSpotterv3测试及训练
XMind 8快捷键史上最全
Renderdoc frame debugger
2018的锅让2019来悲
小程序云开发出坑系列(一)
Openstack build enterprise private cloud - environment preparation
随机推荐
idea读取配置文件如ValidationMessages.properties中文乱码
Swagger(或Postman)关于日期类型的传参方式
七牛云刷新CDN缓存
idea的Database无法提示表名、字段名、无法加载schema问题
Learning Placeholders for Open-Set Recognition
Opensmax: unknown domain generation algorithm detection ecai2020 open set identification paper interpretation
Eureka强制下线服务
11. 处理机调度的概念、层次
8. Process
Towards Open World Object Detection
Samsung S10 series configuration price exposure: 5g version price or more than 10000 yuan!
BERT 详解
idea启动项目失败 YAMLException 中文文件编码格式
promise
MobileNet,从V1到V3
Ampere Altra Max 提供可持续的高分辨率 H.265 编码
Oracle notes
图像处理之阴影检测实例BDRAR
Roommates master binary tree while playing cloud top (super detailed)
Mobilenet, from V1 to V3