def getRestClient(url: String): RestClient = {
val restClientBuilder = RestClient.builder(HttpHost.create(url))
val provider = new BasicCredentialsProvider()
provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user", "password"))
restClientBuilder.setHttpClientConfigCallback((httpClientBuilder: HttpAsyncClientBuilder) => {
httpClientBuilder.disableAuthCaching()
httpClientBuilder.setDefaultCredentialsProvider(provider)
})
val restClient = restClientBuilder.build()
restClient
}
参考文章: