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# Go Java PHP Python node.js 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 . Collections . Generic ;
using System . Linq ;
using System . Net ;
using System . Net . Http ;
using System . Text ;
using System . Threading . Tasks ;
class csharp_http_region
{
static void Main ( string [] args)
{
Task t = new Task (DownloadPageAsync);
t . Start ();
Console . ReadLine ();
}
static async void DownloadPageAsync ()
{
string page = "https://ipinfo.thordata.com" ;
String username = "username" ;
String password = "password" ;
String country = "us" ;
String sessid = "a123123" ;
int sesstime = 10 ;
String proxyUserName = $"user-{username}-region-{country}-sessid-{sessid}-sesstime-{sesstime}" ;
var proxy = new WebProxy ( "http://t.pr.thordata.net:12233" )
{
UseDefaultCredentials = false ,
Credentials = new NetworkCredential (
userName : proxyUserName ,
password : password)
};
var httpClientHandler = new HttpClientHandler ()
{
Proxy = proxy ,
};
var client = new HttpClient (handler : httpClientHandler , disposeHandler : true );
var response = await client . GetAsync (page);
using ( HttpContent content = response . Content )
{
string result = await content . ReadAsStringAsync ();
Console . WriteLine (result);
Console . WriteLine ( "Press any key to exit." );
Console . ReadKey ();
}
}
}
Copy package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
)
const (
resourceUrl = "https://ipinfo.thordata.com"
proxyHost = "t.pr.thordata.net:12233"
username = "username"
password = "password"
country = "us"
sessid = "a123123"
sesstime = 10
)
func main () {
proxyUserName := fmt. Sprintf ( "user- %s -region- %s -sessid- %s -sesstime- %d " , username, country, sessid, sesstime)
proxyUrl := & url . URL {
Scheme: "http" ,
User: url. UserPassword (proxyUserName, password),
Host: proxyHost,
}
client := http . Client {
Transport: & http . Transport {
Proxy: http. ProxyURL (proxyUrl),
},
}
resp, err := client. Get (resourceUrl)
if err != nil {
log. Fatal (err)
}
defer resp.Body. Close ()
body, err := ioutil. ReadAll (resp.Body)
if err != nil {
log. Fatal (err)
}
bodyString := string (body)
fmt. Println (bodyString)
}
Copy import org . apache . http . HttpHost ;
import org . apache . http . auth . AuthScope ;
import org . apache . http . auth . UsernamePasswordCredentials ;
import org . apache . http . client . CredentialsProvider ;
import org . apache . http . client . methods . CloseableHttpResponse ;
import org . apache . http . client . methods . HttpGet ;
import org . apache . http . impl . client . BasicCredentialsProvider ;
import org . apache . http . impl . client . CloseableHttpClient ;
import org . apache . http . impl . client . HttpClients ;
import org . apache . http . impl . conn . BasicHttpClientConnectionManager ;
import org . apache . http . util . EntityUtils ;
import java . io . IOException ;
public class JavaHttpRegionCitySession {
public static final String username = "username" ;
public static final String password = "password" ;
public static final int port = 12233 ;
public static final String region = "us" ;
public static final String sessid = "a123123" ;
public static final int sesstime = 10 ;
public static final String proxyHost = "t.pr.thordata.net" ;
public static final String proxyname = String . format ( "user-%s-region-%s-sessid-%s-sesstime-%s" , username , region , sessid , sesstime);
public CloseableHttpClient client;
public JavaHttpRegionCitySession () {
HttpHost proxy = new HttpHost(proxyHost , port) ;
CredentialsProvider cred_provider = new BasicCredentialsProvider() ;
cred_provider . setCredentials ( new AuthScope(proxy) ,
new UsernamePasswordCredentials(proxyname , password) );
client = HttpClients . custom ()
. setConnectionManager ( new BasicHttpClientConnectionManager() )
. setProxy (proxy)
. setDefaultCredentialsProvider (cred_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 static void main ( String [] args) throws IOException {
JavaHttpRegionCitySession client = new JavaHttpRegionCitySession() ;
try {
System . out . println ( client . request ( "https://myip.thordata.net" ));
} finally { client . close (); }
}
}
Copy <? php
$url = 'ipinfo.thordata.com' ;
$proxy = 't.pr.thordata.net' ;
$port = 12233 ;
$user = 'username' ;
$psw = 'password' ;
$country = 'us' ;
$sessid = 'a123123'
$sesstime = 10
$proxyuser = sprintf ( "user-%s-region-%s-sessid-%s-sesstime-%s" , $user , $country , $sessid , $sesstime ) ;
$ch = curl_init ( $url ) ;
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ) ;
curl_setopt ( $ch , CURLOPT_PROXY , "$proxy:$port" ) ;
curl_setopt ( $ch , CURLOPT_PROXYUSERPWD , "$proxyuser:$psw" ) ;
$result = curl_exec ( $ch ) ;
curl_close ( $ch ) ;
if ($result)
{
echo $result . PHP_EOL ;
}
?>
Copy import requests
username = "username"
password = "password"
proxy_server = "t.pr.thordata.net:12233"
country = "us"
sessid = "a123123"
sesstime = 10
proxies = {
"http" : f "http://user- { username } -region- { country } -sessid- { sessid } -sesstime- { sesstime } : { password } @ { proxy_server } "
}
response = requests . get ( "http://ipinfo.thordata.com" , proxies = proxies)
print (response.text)
Copy const rp = require('request-promise');
const username = "username";
const password = "password";
const proxyServer = "t.pr.thordata.net:12233";
const country = "us";
const sessid = "a123123"
const sesstime = "10"
rp({
url: 'http://ipinfo.thordata.com',
proxy: `http://user-${username}-region-${country}-sessid-${sessid}-sesstime-${sesstime}:${password}@${proxyServer}`,
})
.then(function(data) {
console.log(data);
})
.catch(function(err) {
console.error(err);
});
Copy require "uri"
require 'net/http'
proxy_host = 't.pr.thordata.net'
proxy_port = 12233
proxy_username = 'username'
proxy_pass = 'password'
proxy_country = 'us'
proxy_sessid = 'a123123'
proxy_sesstime = 10
proxy_user = "user- #{proxy_username} -region- #{proxy_country} -sessid= #{proxy_sessid} -sesstime= #{proxy_sesstime} "
uri = URI . parse( 'https://ipinfo.thordata.com' )
proxy = Net :: HTTP :: Proxy (proxy_host , proxy_port , proxy_user , proxy_pass)
req = Net :: HTTP :: Get . new (uri)
result = proxy . start(uri . host , uri . port , use_ssl: true ) do | http |
http . request(req)
end
puts result . body