Backconnect Proxy Service with authorization in JAVA

Working with a Backconnect proxy service ( we spent a long time looking for a way to authorize it. Originally we used JSoup to get the web pages’ content. The proxy() method can be used there when setting up the connection, yet it only accepts the host and port, no authentication is possible. One of the options that we found, was the following:



class ProxyAuthenticator extends Authenticator {

    private String user, password;

    public ProxyAuthenticator(String user, String password) {
        this.user = user;
        this.password = password;

    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(user, password.toCharArray());

This option worked for us, but not always. When testing thru we got the proxy working, but when testing at other sites the proxy didn’t work as intended. While trying to set proxy authorization for in the code, we found the following useful code in Oxylab’s documentation:

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        String url = "";
        String host = "";
        String port = 7777;
        String login = "xxxx";
        String password = "xxxx";

        HttpHost entry = new HttpHost(host, port);
        String query = Executor.newInstance()
            .auth(entry, login, password).execute(Request.Get(url).viaProxy(entry))

Class HttpHost, from the documentation:
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line.

Source: Oxylab documentation.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.