title: Unable to use GET Method
body: <p>I am trying to write a code which will give me the contents of the page as the response in a string using GET method in java.
  Below is the code I am using, its throwing me error that <code>java.net.MalformedURLException: no protocol</code></p>
  
  <p>If I try inserting http:// in starting of the URL its giving me <code>Unknown Host Exception.</code></p>
  
  <pre><code>    String request = ("http://gotoanswer.com/?q=What+is+the+Java+equivalent+for+the+following+in+curl%3F");
      System.out.println(request);
      URL url = null;
  
      try{
          new URL(request);
          HttpURLConnection connection = (HttpURLConnection) new URL(request).openConnection();           
          connection.setDoOutput(true); 
          connection.setInstanceFollowRedirects(false); 
          connection.setRequestMethod("GET"); 
          connection.setRequestProperty("Content-Type", "text/xml"); 
          connection.setRequestProperty("charset", "utf-8");
          connection.connect();
  
          Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
          for ( int c = in.read(); c != -1; c = in.read() )
              System.out.print((char)c);
      }
      catch(IOException e){
          System.out.println(e);
      }
  </code></pre>