restTemplate 发送post 请求
程序员文章站
2022-06-24 22:26:08
...
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
String REQUEST_SN = UUIDUtils.generate32BitId();
//请求***,企业随机生成
headers.add("REQUEST_SN",REQUEST_SN);
//商户号
headers.add("CUST_ID",zcStation.getMerchantId());
//操作员账号
headers.add("USER_ID",zcStation.getUserId());
//操作员交易密码
headers.add("PASSWORD",zcStation.getPassword());
//交易码
headers.add("TX_CODE","5W1004");
//语言
headers.add("LANGUAGE","CN");
//请求体内容
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("ORDER", orderNo);
map.add("MONEY", zcBookedEntity.getPrice().toString());
//构建请求参数,包括请求头,请求体body
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
//发送请求
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
上一篇: Java日期加减运算
下一篇: AsyncTask+HttpClient