title: How to consume a HTTPS GET service with Spring Boot
body: <p>I am trying to consume the following HTTPS endpoints from Yahoo Weather Service:</p>
  
  <p><a href="https://developer.yahoo.com/weather/" rel="nofollow noreferrer" title="Yahoo Weather Service API">Yahoo Weather Service API</a></p>
  
  <p>I am doing some special query according to the API to get the current weather at some parametrized location.</p>
  
  <pre><code>@Service("weatherConditionService")
  public class WeatherConditionServiceImpl implements WeatherConditionService {
  
      private static final String URL = "http://query.yahooapis.com/v1/public/yql";
  
      public WeatherCondition getCurrentWeatherConditionsFor(Location location) {
          RestTemplate restTemplate = new RestTemplate();
          StringBuilder stringBuilder = new StringBuilder();
          stringBuilder.append(URL);
          stringBuilder.append("?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22");
          // TODO: Validate YQL query injection
          stringBuilder.append(location.getName());
          stringBuilder.append("%22)&amp;format=json&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
          WeatherQuery weatherQuery = restTemplate.getForObject(stringBuilder.toString(), WeatherQuery.class);
          // TODO: Test Json mapping response
          Condition condition = weatherQuery.getQuery().getResults().getChannel().getItem().getCondition();
          return new WeatherCondition(condition.getDate(), Integer.parseInt(condition.getTemp()), condition.getText());
      }
  </code></pre>
  
  <p>Location is a class that provides the attribute "name" that is a String description of the location, such as "New York" or "Manila".</p>
  
  <p>Condition an other classes just map the returning object.</p>
  
  <p>When executing I get the following HTTP response:</p>
  
  <pre><code>org.springframework.web.client.HttpClientErrorException: 403 Forbidden
  </code></pre>
  
  <p>So this means I am not authorized to access the resource from what I understand.</p>
  
  <p>The URL works great if I just copy &amp; paste it in a web browser:</p>
  
  <p><a href="https://query.yahooapis.com/v1/public/yql?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20%3D%202487889&amp;format=json&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys" rel="nofollow noreferrer">Yahoo Weather Query</a></p>
  
  <p>I think that mapping is not a problem since I am not getting "400" (Bad Request) but "403" (Forbidden)</p>
  
  <p>There must be some error on the way I use the RestTemplate object. I am researching but I can't find an answer.</p>