LWP::UserAgent is Perl's standard HTTP client library. Connect to KnoxProxy with a single proxy() call and full HTTPS tunnel support.
Install the LWP modules from CPAN.
cpan install LWP::UserAgent LWP::Protocol::httpsConfigure LWP::UserAgent with KnoxProxy.
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
$ua->proxy(['http', 'https'], 'http://USER:PASS@gw.knoxproxy.com:7000');Send a GET request through the proxy.
my $response = $ua->get('https://httpbin.org/ip');
if ($response->is_success) {
print $response->decoded_content;
} else {
die $response->status_line;
}Target a specific country in the proxy username.
$ua->proxy(['http', 'https'], 'http://USER-country-de:PASS@gw.knoxproxy.com:7000');Use env_proxy to read from environment variables.
# Set in shell:
# export http_proxy=http://USER:PASS@gw.knoxproxy.com:7000
# export https_proxy=http://USER:PASS@gw.knoxproxy.com:7000
my $ua = LWP::UserAgent->new();
$ua->env_proxy;Add targeting headers and configure timeouts.
$ua->timeout(30);
$ua->default_header('X-KnoxProxy-Country' => 'jp');
my $response = $ua->get('https://httpbin.org/ip');
print $response->decoded_content;#!/usr/bin/env perl
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new(
timeout => 30,
agent => 'KnoxProxy-Perl/1.0',
);
$ua->proxy(['http', 'https'], 'http://USER:PASS@gw.knoxproxy.com:7000');
my $response = $ua->get('https://httpbin.org/ip');
if ($response->is_success) {
print "Exit IP: " . $response->decoded_content . "\n";
} else {
die "Request failed: " . $response->status_line . "\n";
}Each request gets a new exit IP by default. For sticky sessions, use USER-session-{id} in the proxy URL (e.g., http://USER-session-myid:PASS@gw.knoxproxy.com:7000).
| Problem | Fix |
|---|---|
| 500 Can't connect to gw.knoxproxy.com:7000 | Install LWP::Protocol::https: cpan install LWP::Protocol::https. Verify port 7000 is not blocked by firewall. |
| 407 Proxy Authentication Required | Check username and password. URL-encode special characters (e.g., @ becomes %40 in the password). |
USER-country-de-city-berlin-session-profile07Order matters -- geo flags before the session flag. The session name is free text; use the profile ID so the mapping is self-documenting. Password stays as issued; no flags belong there. HTTP on :7000, SOCKS5 on :7001, same credentials.
Install the LWP::Protocol::socks module from CPAN alongside the base LWP::UserAgent and LWP::Protocol::https modules already required for HTTPS support. Then call $ua->proxy(["http", "https"], "socks://USER:PASS@gw.knoxproxy.com:7001") using the dedicated KnoxProxy SOCKS5 port 7001 instead of the HTTP port 7000 used in the standard setup shown above.
Yes. Set the http_proxy and https_proxy environment variables in your shell, then call $ua->env_proxy so LWP::UserAgent reads them automatically instead of hardcoding credentials in your script. This keeps credentials out of source code, though you must set the variables again in every new shell session.
Each call to $ua->get() or $ua->post() gets a fresh exit IP by default, so no extra configuration is needed for rotation. If you need the same IP across multiple requests instead, add a session ID to the proxy username, like USER-session-myid, in the proxy URL passed to $ua->proxy().
Mojo::UserAgent is a separate module from LWP::UserAgent and uses a different proxy API, so the setup steps above do not carry over directly. Instead, call $ua->proxy->http("http://USER:PASS@gw.knoxproxy.com:7000") to point the Mojo client at the KnoxProxy gateway on port 7000 shown throughout this guide.
Rotating residential proxies -- 3 minutes setup, instant activation, 14-day money-back guarantee.