Using RestTemplate in Spring. Exception- Not enough variables available to expand

前端 未结 6 1136
走了就别回头了
走了就别回头了 2020-11-29 05:29

I am trying to access the contents of an API and I need to send a URL using RestTemplate.

String url1 = \"http://api.example.com/Search?key=52ddafbe3ee659bad         


        
6条回答
  •  一生所求
    2020-11-29 06:09

    You can simply append a variable key to the URL and give the value using the restTemplate.getForObject() method.

    Example:

    String url = "http://example.com/api?key=12345&sort={data}";
    String data="{\"price\":\"desc\"}";
    
    OutputPage page = restTemplate.getForObject(url, OutputPage.class, data);
    

提交回复
热议问题