title: How to fix UnknownHostException in Java, calling rest-api?
body: <p>I have a simple rest-api call but I keep getting unknownHostException even after changing to a different Test API. I've never really done anything with rest-api. Below I have added the Stacktrace. When I open the website that I'm trying to access I can see all the Content.</p>
  
  <pre><code>java.net.UnknownHostException: dummy.restapiexample.com
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:589)
      at java.net.Socket.connect(Socket.java:538)
      at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
      at sun.net.www.http.HttpClient.&lt;init&gt;(HttpClient.java:211)
      at sun.net.www.http.HttpClient.New(HttpClient.java:308)
      at sun.net.www.http.HttpClient.New(HttpClient.java:326)
      at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1168)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)
      at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:932)
      at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1282)
      at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1257)
      at restApi.MainApp.main(MainApp.java:26)
  
  public static void main(String[] args) {
          URL url;
          try {
              url = new URL("http://dummy.restapiexample.com/api/v1/employees");
              String query = "";
              //make connection
              URLConnection urlc = url.openConnection();
  
              //use post mode
              urlc.setDoOutput(true);
              urlc.setAllowUserInteraction(false);
  
              //send query
              PrintStream ps = new PrintStream(urlc.getOutputStream());
              ps.print(query);
              ps.close();
  
              //get result
              BufferedReader br = new BufferedReader(new InputStreamReader(urlc
                  .getInputStream()));
              String l = null;
              while ((l=br.readLine())!=null) {
                  System.out.println(l);
              }
              br.close();
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }```
  </code></pre>