RestTemplate如何发送带headers的GET请求,以

2019-11-07  本文已影响0人  sparkle777

参考:https://blog.csdn.net/asahinokawa/article/details/86497531

https://blog.csdn.net/clj198606061111/article/details/70227571

https://blog.csdn.net/u010180738/article/details/61439630

GET加headers:

HttpHeaders httpHeaders =new HttpHeaders();

httpHeaders.set("head1", "head1");

httpHeaders.set("head2", "head2");

String url = "https://test.com/api";

ResponseEntity response =restTemplate.exchange(url, HttpMethod.GET,new HttpEntity(httpHeaders), String.class);

PUT带返回值:

HttpHeaders httpHeaders =new HttpHeaders();

httpHeaders.setContentType(MediaType.APPLICATION_XML);

httpHeaders.set("head1", "head1");

httpHeaders.set("head2", "head2");

String url = "https://test.com/api";

String body= "body";

HttpEntity entity =new HttpEntity<>(body, httpHeaders);

String url = "https://test.com/api";

ResponseEntity response =restTemplate.exchange(url, HttpMethod.PUT, entity, String.class);

上一篇 下一篇

猜你喜欢

热点阅读