code: public static HttpResponse getHttpResponse(String url, UsernamePasswordCredentials credentials) throws IOException {
          HttpGet request = new HttpGet(url);
          if (credentials != null) {
              URI uri = request.getURI();
              AuthScope authScope = new AuthScope(uri.getHost(), uri.getPort());
              Credentials cached = httpClient.getCredentialsProvider().getCredentials(authScope);
              if (!areSame(cached, credentials)) {
                  httpClient.getCredentialsProvider().setCredentials(authScope, credentials);
              }
          }
          return httpClient.execute(request);
      }
docs: Executes a request using the given URL and credentials.
  
  @param url  the http URL to connect to.
  @param credentials credentials to use
  
  @return  the response to the request.
  @throws IOException in case of a problem or the connection was aborted
  @throws ClientProtocolException in case of an http protocol error