Apache HTTP Client/Commons with User authentication : Need to do HTTP GET with UserId/password Authentication using Apache HTTP Client/Commons lib:

    val targetHost = new HttpHost("url", 8080, "http");
    val credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY,
    new UsernamePasswordCredentials("user", "password"));
    val authCache = new BasicAuthCache();
    authCache.put(targetHost, new BasicScheme());
    val context = HttpClientContext.create();
    context.setCredentialsProvider(credsProvider);
    context.setAuthCache(authCache);
    val client = HttpClientBuilder.create().build();
    var response = client.execute(
    new HttpGet("url"), context);
    var statusCode = response.getStatusLine().getStatusCode();

But not able to fetch the data from the URL as it is failing to connect to the URL.Please can someone assist

