美文网首页
RestTemplate如何发送带headers的GET请求,以

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

作者: sparkle777 | 来源:发表于2019-11-07 10:57 被阅读0次

    参考: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);

    相关文章

      网友评论

          本文标题:RestTemplate如何发送带headers的GET请求,以

          本文链接:https://www.haomeiwen.com/subject/vgvmbctx.html