title: Efficiently making multiple GET requests to the same url in Java
body: <p>I need to make multiple GET requests to the same URL but with different queries. I will be doing this on a mobile device (Android) so I need to optimise as much as possible. I learnt from watching an Android web seminar by Google that it takes ~200ms to connect to a server and there's also various other delays involved with making data calls. I'm just wondering if theres a way I can optimise the process of making multiple requests to the same URL to avoid some of these delays?</p>
  
  <p>I have been using the below method so far but I have been calling it 6 times, one for each GET request. </p>
  
  <pre><code>//Make a GET request to url with headers.
  //The function returns the contents of the retrieved file
  
  public String getRequest(String url, String query, Map&lt;String, List&lt;String&gt;&gt; headers) throws IOException{
      String getUrl = url + "?" + query;
      BufferedInputStream bis = null;
      try {
          connection = new URL(url + "?" + query).openConnection();
          for(Map.Entry&lt;String, List&lt;String&gt;&gt; h : headers.entrySet()){
              for(String s : h.getValue()){
                  connection.addRequestProperty(h.getKey(), s);
              }
          }
  
          bis = new BufferedInputStream(connection.getInputStream());
          StringBuilder builder = new StringBuilder();
          int byteRead;
          while ((byteRead = bis.read()) != -1)
              builder.append((char) byteRead);
  
          bis.close();
          return builder.toString();
      } catch (MalformedURLException e) {
          throw e;
      } catch (IOException e) {
          throw e;
      }
  }
  </code></pre>