import org.apache.http.HttpHost;
import org.apache.http.auth.*;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.*;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
public static final String username = "USERNAME";
public static final String password = "PASSWORD";
public String session_id = Integer.toString(new Random().nextInt(Integer.MAX_VALUE));
public CloseableHttpClient client;
String login = "customer-"+username+"-sessid-" + session_id;
HttpHost entry_node = new HttpHost("dc.de-pr.oxylabs.io:40000");
CredentialsProvider credentials_provider = new BasicCredentialsProvider();
credentials_provider.setCredentials(new AuthScope(entry_node),
new UsernamePasswordCredentials(login, password));
client = HttpClients.custom()
.setConnectionManager(new BasicHttpClientConnectionManager())
.setDefaultCredentialsProvider(credentials_provider)
public String request(String url) throws IOException {
HttpGet request = new HttpGet(url);
CloseableHttpResponse response = client.execute(request);
return EntityUtils.toString(response.getEntity());
} finally { response.close(); }
public void close() throws IOException { client.close(); }
public static void main(String[] args) throws IOException {
Client client = new Client();
System.out.println(client.request("https://ip.oxylabs.io"));
} finally { client.close(); }