如何使用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]}“
所以我假设服务器有一些控制器(你可以调整差异部分为你工作它只是一个例子):
@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'