我如何使用resttemplate调用以下Web服务
curl -v POST --cert kkk.cer --key kkk.private --pass kkk --cacert sslservercachain.cer“ https://hello-sign.api-dev.myname.com/v1/gkscl/1p1/services/filesLocation” -H“授权:Bearer zxAM4M90964ae” -d“ {\” fileids \“:[1、21、22]}”
答案 0 :(得分:0)
因此,我假设服务器具有类似的控制器(您可以调整不同部分以使其适合您,这只是一个示例):
@PostMapping
public ResponseEntity somePost(@RequestBody PostRequestObject request)
{
// logic
}
为发送请求创建相应的类:
@Data
class PostRequestObject {
List<Integer> data;
}
使用resttemplate发送请求:
PostRequestObject request = new PostRequestObject();
request.setData(Arrays.asList(1,21,22));
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + "zxAM4M90964ae");
HttpEntity<Object> requestEntity = new HttpEntity<Object>(request, headers);
ResponseEntity<YourResponseClass> result = restTemplate.exchange(
"https://hello-sign.api-dev.myname.com/v1/gkscl/1p1/services/filesLocation",
HttpMethod.POST,
requestEntity,
YourResponseClass.class);
在-d之后尝试:
'fields[]=1&fields[]=21&fields[]=22'