Session Control
Adding the sessid
parameter with a session ID string, for example, sessid-abc12345
, to the user name enables session control. The proxy is not changed with the following requests and the session does not expire. The example below shows how session control works:
Your initial query with
sessid-random123
got assigned proxy IP address1.1.1.1
As long as you keep sending new requests with the same session ID, the system will route your queries through
1.1.1.1
Credentials list example:
Example represents a list of credentials that establish different sessions.
customer-USERNAME-sessid-iqwcp:PASSWORD
customer-USERNAME-sessid-tevab:PASSWORD
customer-USERNAME-sessid-6drwn:PASSWORD
customer-USERNAME-sessid-7eh7g:PASSWORD
customer-USERNAME-sessid-z7cao:PASSWORD
Code examples
German IP is chosen for the first request, and then the same IP is kept with new queries (session control):
curl -x dc.de-pr.oxylabs.io:40000 -U "customer-USERNAME-sessid-abcde12345:PASSWORD" https://ip.oxylabs.io/location
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$session = mt_rand();
$proxy = 'dc.de-pr.oxylabs.io:40000';
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "customer-$username-sessid-$session:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
echo $output;
?>
import urllib.request
import random
username = 'USERNAME'
password = 'PASSWORD'
session = random.random()
entry = ('http://customer-%s-sessid-%s:%s@dc.de-pr.oxylabs.io:40000' %
(username, session, password))
query = urllib.request.ProxyHandler({
'http': entry,
'https': entry,
})
execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read()
package example;
import java.io.*;
import java.util.Random;
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;
class Client {
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;
public 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())
.setProxy(entry_node)
.setDefaultCredentialsProvider(credentials_provider)
.build();
}
public String request(String url) throws IOException {
HttpGet request = new HttpGet(url);
CloseableHttpResponse response = client.execute(request);
try {
return EntityUtils.toString(response.getEntity());
} finally { response.close(); }
}
public void close() throws IOException { client.close(); }
}
public class Example {
public static void main(String[] args) throws IOException {
Client client = new Client();
try {
System.out.println(client.request("https://ip.oxylabs.io/location"));
} finally { client.close(); }
}
}
using System;
using System.Net;
class Client : WebClient
{
public static string username = "USERNAME";
public static string password = "PASSWORD";
public string session_id = new Random().Next().ToString();
public Client(string country_iso = null)
{
this.Proxy = new WebProxy("dc.de-pr.oxylabs.io:40000");
var login = "customer-"+username+"-sessid-"+session_id;
this.Proxy.Credentials = new NetworkCredential(login, password);
}
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address) as HttpWebRequest;
request.ConnectionGroupName = session_id;
return request;
}
}
class Example
{
static void Main()
{
var client = new Client();
Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
}
}
require 'uri'
require 'net/http'
require 'net/https'
entry_node = 'dc.de-pr.oxylabs.io'
entry_port = '40000'
username = 'USERNAME'
password = 'PASSWORD'
session_id = Random.rand(1000000)
uri = URI.parse("https://ip.oxylabs.io/location")
headers = {
'Accept-Encoding' => 'gzip'
}
proxy = Net::HTTP::Proxy(entry_node, entry_port, "#{username}-sessid-#{session_id}", password)
http = proxy.new(uri.host,uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
req = Net::HTTP::Get.new(uri.path, headers)
result = http.start do |con|
con.request(req)
end
puts result.body
Last updated