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.
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.
implementation("org.jsoup:jsoup:1.21.1")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-secretProxyExample.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());
}
}
Keep the important behavior visible.
Add workload-specific controls before scale.
Test representative targets, response sizes, routing policy, concurrency, retries, validation, and completion window. Collect only public data you are authorized to access.
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.