使用restTemplate发包
1.发送application/x-www-form-urlencoded
final String myId = id;
//参数
MultiValueMap<String, String> paramMap = new LinkedMultiValueMap(){
{
add("id", myId);
add("ymbb", TaxFpdkVersionEnum.getValue(taxBureauRequest.getZoneCode()));
}
};
//封装请求头
RequestEntity requestEntity = RequestEntity
.post(new URI("")) // 可以不填
.contentType(MediaType.APPLICATION_FORM_URLENCODED) // 参数传输类型 url编码格式 application/x-www-form-urlencoded
.accept(MediaType.ALL).acceptCharset(StandardCharsets.UTF_8)
.body(paramMap);
//基于注解映射对应实体
ResponseEntity<String> responseEntity = restTemplate.postForEntity(urllogin, requestEntity, String.class);
result = responseEntity.getBody();
2.发送get请求
HttpHeaders headers = new HttpHeaders();
if(oauthloginUrl.startsWith("https://etax") || oauthloginUrl.startsWith("http://etax")){//这个cookie是电子税局的,设置时需要注意
headers.set("Cookie", taxBureauRequest.getCookie());
headers.set("Host", "etax.xinjiang.chinatax.gov.cn");
headers.set("User-Agent", this.userAgent);
}else {
headers.set("Host", "fpdk.xinjiang.chinatax.gov.cn");
headers.set("User-Agent", this.userAgent);
}
HttpEntity<JSONObject> httpEntity = new HttpEntity<>( headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(oauthloginUrl, HttpMethod.GET, httpEntity, String.class);
log.info("xinjiang getToken oauthaccessUrl start:"+oauthloginUrl);
responseCode = responseEntity.getStatusCode().value();
result = responseEntity.getBody();
如有问题,请私信。
tL+8vMr1vbvB96Osx+vO8NPD09q3x7eo08PNvqGjDQoNCsTmz/LP4LnYv86zzKGiSlOyubu3vrO/zrPMoaJKQVZBz+C52L/Os8zI59Do0qrSsr/J0tTBqs+1UVGhow0KDQrX99XfIFFRIDQwNDU0MDIyOQ==
还没有评论,来说两句吧...