调用接口的请求方式

博客展示了接口调用的请求方式代码示例。通过创建 HttpHeaders 和多个 HashMap 存储请求参数,设置请求头签名,构建 HttpEntity,使用 RestTemplate 以 POST 方式向指定 URL 发送请求,并输出请求实体和响应结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HttpHeaders headers = new HttpHeaders();
HashMap<String, Object> signMap1 = new HashMap<String, Object>();
HashMap<String, Object> signMap = new HashMap<String, Object>();
HashMap<String, Object> signMap0 = new HashMap<String, Object>();
signMap.put("appid", "Test");
signMap.put("appkey", "Test");
signMap.put("scenario", "SC01");
signMap.put("interfaceno", "NB00002");
signMap.put("operator", "Test");
signMap.put("timeStamp", "20190123133755275");
signMap1.put("data", signMap);
System.out.println(JsonUtils.transferToJson(signMap1));
headers.add("sign", SignUtil.getSign(signMap1, SignUtil.secretKeyOfWxh));
HttpEntity<String> requestEntity = new HttpEntity<String>(JsonUtils.transferToJsonNoFormat(signMap1), headers);
RestTemplate restTemplate = new RestTemplate();
String post = restTemplate.postForObject("http://10.8.201.47:8080/services/api/authentication/certification", requestEntity, String.class);
System.out.println(requestEntity);
System.out.println(post);

转载于:https://www.cnblogs.com/otways/p/10833212.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值