Session control types include rotating session and sticky session.
Rotate session:
If you want to get a new IP on every request, you can switch the Session settings to rotation mode in the endpoint generator and use it.
Sticky session:
If you want to reserve the same IP address for a certain period of time to run multiple requests, you can switch the Session settings to sticky mode in the endpoint generator and set the duration or use the sessid
parameter + a randomly created alphanumeric after the username String + sesstime
parameter + set duration (minutes), for example, set the sticky mode duration to 10 minutes: sessid-a123123-sesstime-10
.
For example, if you query sessid-a123123-sesstime-10
and it is assigned to the proxy IP address 1.1.1.1
, as long as you keep using the same sessid-a123123-sesstime-10
to send requests and the IP address is available online, the proxy IP address you request will not change. . When the session time exceeds the set 10 minutes, your next request at sessid-a12123-sesstime-10
will be assigned a different proxy IP address, such as 1.1.1.2
.
Please note: We currently support setting a maximum session duration of 90 minutes.
You can also set multiple different session proxy addresses, such as:
Copy user-USERNAME-sessid-a234234-sesstime-15:PASSWORD
user-USERNAME-sessid-a345345-sesstime-30:PASSWORD
user-USERNAME-sessid-a456456-sesstime-45:PASSWORD
user-USERNAME-sessid-a567567-sesstime-90:PASSWORD
Code example:
sessid-a123123-sesstime-10
In this example, the same US IP as the first request is used, and the duration is 10 minutes
cURL C# PHP Python Java Ruby
Copy curl -x t.pr.thordata.net:12233 -U "user-USERNAME-region-US-sessid-a123123-sesstime-10:PASSWORD" ipinfo.thordata.com
Copy 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 static string session_time = "10" ;
public Client ( string country_iso = null )
{
this . Proxy = new WebProxy ( "t.pr.thordata.net:12233" );
var login = "user-" + username + (country_iso != null ? "-region-" + country_iso : "" )
+ "-sessid-" + session_id + "-sesstime-" + session_time;
this . Proxy . Credentials = new NetworkCredential (login , password);
}
protected override WebRequest GetWebRequest ( Uri address)
{
var request = base. GetWebRequest (address) as HttpWebRequest ;
request . ConnectionGroupName = session_id;
request . ConnectionGroupTime = session_time;
return request;
}
}
class Example
{
static void Main ()
{
var client = new Client ( "us" );
Console . WriteLine ( client . DownloadString ( "https://ipinfo.thordata.com" ));
}
}
Copy <? php
$username = 'USERNAME' ;
$password = 'PASSWORD' ;
$country = 'US' ;
$session = mt_rand () ;
$sesstime = 10 ;
$proxy = 't.pr.thordata.net:12233' ;
$query = curl_init ( 'https://ipinfo.thordata.com' ) ;
curl_setopt ( $query , CURLOPT_RETURNTRANSFER , 1 ) ;
curl_setopt ( $query , CURLOPT_PROXY , "http://$proxy" ) ;
curl_setopt ( $query , CURLOPT_PROXYUSERPWD , "user-$username-region-$country-sessid-$session-sesstime-$sesstime:$password" ) ;
$output = curl_exec ( $query ) ;
curl_close ( $query ) ;
if ($output)
echo $output;
?>
Copy import urllib . request
import random
username = 'USERNAME'
password = 'PASSWORD'
country = 'US'
session = random . random ()
sesstime = 10
entry = ( 'http://user- %s -region- %s -sessid- %s -sesstime- %d : %s @t.pr.thordata.net:12233' %
(username , country , city , session , sesstime , password))
query = urllib . request . ProxyHandler ({
'http' : entry,
'https' : entry,
})
execute = urllib . request . build_opener (query)
print (execute. open ( 'https://ipinfo.thordata.com' ). read ())
Copy 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 String sesstime = "10" ;
public CloseableHttpClient client;
public Client ( String country) {
String login = "user-" + username + (country_iso != null ? "-region-" + country_iso : "" ) + "-sessid-" + session_id + "-sesstime-" + sesstime;
HttpHost entry_node = new HttpHost( "t.pr.thordata.net:12233" ) ;
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( "us" ) ;
try {
System . out . println ( client . request ( "https://ipinfo.thordata.com" ));
} finally { client . close (); }
}
}
Copy require 'uri'
require 'net/http'
require 'net/https'
entry_node = 't.pr.thordata.net'
entry_port = '12233'
username = 'USERNAME'
password = 'PASSWORD'
session_id = Random . rand ( 1000000 )
sesstime = 10
uri = URI . parse( "https://ipinfo.thordata.com" )
headers = {
'Accept-Encoding' => 'gzip'
}
proxy = Net :: HTTP :: Proxy (entry_node , entry_port , " #{username} -region-US-sessid- #{session_id} -sesstime- #{sesstime} " , 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