All systems operational HTTP · HTTPS · SOCKS5 Global network
Documentation home Quickstart Engineering guides Code examples Global network Pricing Solutions overview Custom proxy pools Managed data scraping Contact Console
CODE EXAMPLE

Send authenticated proxy requests with Java and Jsoup.

Send authenticated proxy requests with Java and Jsoup. This example uses Rotating Proxies as the default gateway and can be adapted by replacing endpoint and routing credentials.

LanguageJava 17+FrameworkJsoupGatewayRotating ProxiesFileProxyExample.java
01
SETUP

Install the client and create a file.

Use a clean project environment and pin tested dependency versions for production. The example target is a public scraping sandbox.

Installimplementation("org.jsoup:jsoup:1.21.1")
02
CREDENTIALS

Load proxy secrets from the environment.

The proxy username is not the LundProxy website login. Copy the complete username and password generated for the selected proxy product.

PROXY_USER=user-pool-crawlerPROXY_PASS=your-secret
03
COMPLETE EXAMPLE

ProxyExample.java

Copy the code into the named file, set credentials, and run it from the project environment.

import java.net.PasswordAuthentication;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class ProxyExample {
    public static void main(String[] args) throws Exception {
        Connection connection = Jsoup
            .connect("https://quotes.toscrape.com/")
            .proxy("proxy.lundproxy.com", 36923)
            .auth(context -> {
                if (!context.isProxy()) return null;
                return new PasswordAuthentication(
                    System.getenv("PROXY_USER"),
                    System.getenv("PROXY_PASS").toCharArray()
                );
            })
            .timeout(30_000);

        Document document = connection.get();
        System.out.println(document.select(".quote").size());
    }
}
04
WHAT THE EXAMPLE DOES

Keep the important behavior visible.

01Authentication responds only to proxy challenges.
02Timeout is explicit.
03Proxy host and port are not parsed from user input.
04Credential values remain outside source code.
05
PRODUCTION NOTES

Add workload-specific controls before scale.

A successful sandbox run proves integration, not production readiness.

Test representative targets, response sizes, routing policy, concurrency, retries, validation, and completion window. Collect only public data you are authorized to access.

06
EXAMPLE FAQ

Jsoup questions.

Why check isProxy?

It prevents proxy credentials from being returned for unrelated authentication challenges.

Can the Connection be reused?

Use a Jsoup session when multiple requests should share client state.

How do I switch country?

Use the complete Premium Residential username generated for that country.