请求参数封装
@Data
public class ClientCertificateDto {
private String companyCode;
private String uniqueCompanySign;
private String companyName;
}
请求方式 get,调用:http://www.ccb.com/clientConstruct/getCilentCertificate
public class RestTemplateUtilsDemo {
public static void main(String[] args) {
String url = "http://www.ccb.com/clientConstruct/getCilentCertificate";
ClientCertificateDto clientCertificateDto = new ClientCertificateDto();
clientCertificateDto.setCompanyCode("16654646446464646465");
clientCertificateDto.setUniqueCompanySign("15151555151515155");
clientCertificateDto.setCompanyName("量子实验室");
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
httpHeaders.add("Authorization", "Bearer " + "token");
httpHeaders.add("bankSign", "bankSign");
Map<String, Object> map = new HashMap<>();
map.put("companyCode",clientCertificateDto.getCompanyCode());
map.put("uniqueCompanySign",clientCertificateDto.getUniqueCompanySign());
map.put("companyName",clientCertificateDto.getCompanyName());
log.info("get请求获取合作客户的证书:链接:{},dto:{}",url, JSON.toJSONString(clientCertificateDto));
String jsonObject = RestTemplateUtils.post(null, url + "?companyCode={companyCode}&uniqueCompanySign={uniqueCompanySign}&companyName={companyName}",null, httpHeaders, String.class,map);
log.info("get请求获取合作客户的证书返回结果:{}",JSON.toJSONString(jsonObject));
}
}
实际开发种,很少使用get请求,暂时分享到此。若有疑问,可留言。