How do I add basic authentication for the default client of the httpClient library? I have seen examples where they use client.getCredentialProvider()
, however I th
Another modern option for 4.3 is to use the Fluent extension:
Executor executor = Executor.newInstance()
.auth(new HttpHost("somehost"), "username", "password")
.auth(new HttpHost("securehost", 443, "https"), "username", "password") // https example
.auth(new HttpHost("myproxy", 8080), "username", "password")
.authPreemptive(new HttpHost("myproxy", 8080));
String content = executor.execute(Request.Get("http://somehost/"))
.returnContent().asString();