title: Weather API call from Java web application
body: <p>I am calling an api: openweathermap.org. If I call the url (strUri as formed in the below code after passing the city name and API key properly) directly in the address bar, it works fine but from the application, it throws an exception as:</p>
  
  <p>api.openweathermap.org; nested exception is java.net.UnknownHostException: api.openweathermap.org.</p>
  
  <p>java.net.UnknownHostException: api.openweathermap.org
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178) ~[na:1.7.0_51]</p>
  
  <p>Please help. I am using RESTTemplate and spring-boot for the application.</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public String weatherPost(@ModelAttribute City city, ModelMap model) throws URISyntaxException{
      String apiKey="myApIKey";//Removed my original API Key for posting.
      RestTemplate template = new RestTemplate();
      String strUri= "http://api.openweathermap.org/data/2.5/weather?q="+city.getName()+",AU&amp;appid="+apiKey+"&amp;units=metric";
      URI uri = new URI(strUri);
      RequestEntity&lt;String&gt; request = new RequestEntity&lt;String&gt;(HttpMethod.GET,uri);
      ResponseEntity &lt;WeatherResponse&gt; weatherResponse = template.exchange(uri, HttpMethod.GET, request, WeatherResponse.class);
      City myCity = new City();
      model.put("weatherResponse", weatherResponse);
      model.put("city", myCity);
      return "weather";
  }
  </code></pre>