Thordata Docs
简体中文
简体中文
  • 概述
  • 代理
    • 集成教程
      • 住宅代理集成
        • AdsPower
        • BitBrowser
        • ClonBrowser
        • Hubstudio
        • Playwright
        • Puppeteer
        • Selenium
        • Ghost Browser
        • SwitchyOmega
        • FoxyProxy
        • Chrome
        • Edge
        • MuLogin
      • ISP代理集成
        • AdsPower
        • BitBrowser
        • ClonBrowser
        • Hubstudio
        • Ghost Browser
        • SwitchyOmega
        • FoxyProxy
        • Chrome
        • Edge
      • 数据中心代理集成
        • AdsPower
        • BitBrowser
        • ClonBrowser
        • Hubstudio
        • Ghost Browser
        • SwitchyOmega
        • FoxyProxy
        • Chrome
        • Edge
      • 无限代理集成
        • AdsPower
        • BitBrowser
        • ClonBrowser
        • Hubstudio
        • Ghost Browser
        • SwitchyOmega
        • FoxyProxy
        • Chrome
        • Edge
    • 住宅代理
      • 入门指南
      • 端点生成器
        • 账密认证
        • IP白名单
          • 国家条目提取
            • 国家/地区入口节点
          • API链接
      • 账户
      • 基本查询
      • 位置设置
        • 国家/地区
        • 城市
        • 州
      • 会话控制
      • 协议
      • 国家/地区列表
      • CDKEY生成与兑换
    • ISP代理
      • 入门指南
    • 数据中心代理
      • 入门指南
    • 无限代理服务器
      • 端点生成器
        • 账密认证
        • IP白名单
          • 国家条目提取
          • API链接
      • 账户
      • 国家/地区列表
  • 爬取
    • SERP API
      • 入门指南
      • API实验场
      • 发送您的第一次请求
      • 解析后的JSON结果
      • SERP API Google 查询参数
      • SERP API Bing 查询参数
  • WEB Scraper API
    • 入门指南
    • API 请求构建器
    • 抓取参数说明
  • Universal Scraping API
    • 入门指南
    • 配置
    • 参数说明
  • 免费工具
    • 谷歌扩展程序
      • 使用教程
  • 有用的链接
    • 仪表板中心
  • 常见问题
    • 产品问题
      • 我该如何选择合适的代理套餐?
      • 如何定位特定的国家/地区?
      • 如何定位特定的城市?
      • 什么是无限代理?
      • IP检测结果与购买提取的地区不符?
    • 付款问题
      • 支持哪些支付方式?
      • 购买错套餐怎么办?
      • 是否提供付费服务退款?
      • 付款后,收到代理余额或激活我的帐户需要多长时间?
  • 支持
    • 联系我们
Powered by GitBook
On this page

Was this helpful?

  1. 代理
  2. 住宅代理

会话控制

Previous州Next协议

Last updated 3 months ago

Was this helpful?

会话控制类型包含轮换会话和粘性会话两种

轮换会话:

如果您希望在每次请求时都能获取新的IP,您可以在中切换会话设定为轮换模式并使用。

黏性会话:

如果您希望在一定时间内保留相同的IP地址来运行多个请求,您可以在中切换会话设定为黏性模式并设定持续时间或在用户名后使用sessid参数+随机创建的字母数字字符串+sesstime参数+设定的持续时间(分钟),例如设定黏性模式持续时间为10分钟:sessid-a123123-sesstime-10。

比如您查询sessid-a123123-sesstime-10被分配至代理IP地址1.1.1.1,只要您保持使用相同的sessid-a123123-sesstime-10发送请求并且IP地址在线可用的情况下,您请求的代理IP地址将不会变更。当会话时间超过设定的10分钟时,您在sessid-a12123-sesstime-10的下一个请求将分配不同的代理IP地址,例如1.1.1.2。

请注意:当前我们支持设定最高持续时间为90分钟。

您也可以设定多条不同的会话代理地址,比如:

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

代码示例:

sessid-a123123-sesstime-10在此示例中,使用与第一次请求相同的美国IP,并且持续时间为10分钟

curl -x t.pr.thordata.net:9999 -U "td-customer-USERNAME-country-US-sessid-a123123-sesstime-10:PASSWORD" ipinfo.thordata.com 
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 = $"td-customer-{username}-country-{country}-sessid-{sessid}-sesstime-{sesstime}";


        var proxy = new WebProxy("http://t.pr.thordata.net:9999")
        {
            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();

        }
    }
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
)

const (
	resourceUrl = "https://ipinfo.thordata.com"
	proxyHost   = "t.pr.thordata.net:9999"
	username    = "username"
	password    = "password"
	country     = "us"
	sessid      = "a123123"
	sesstime    = 10
)

func main() {
	proxyUserName := fmt.Sprintf("td-customer-%s-country-%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)
}
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 = 9999;

    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("td-customer-%s-country-%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(); }
    }
}
<?php
  $url = 'ipinfo.thordata.com';
  $proxy = 't.pr.thordata.net';
  $port = 9999;
  $user = 'username';
  $psw = 'password';
  $country = 'us';

  $sessid = 'a123123'
  $sesstime = 10
  $proxyuser = sprintf("td-customer-%s-country-%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;
  }
?>
import requests


username = "username"
password = "password"
proxy_server = "t.pr.thordata.net:9999"
country = "us"
sessid = "a123123"
sesstime = 10

proxies = {
    "http": f"http://td-customer-{username}-country-{country}-sessid-{sessid}-sesstime-{sesstime}:{password}@{proxy_server}"
}
response = requests.get("http://ipinfo.thordata.com", proxies=proxies)
print(response.text)
const rp = require('request-promise');

const username = "username";
const password = "password";
const proxyServer = "t.pr.thordata.net:9999";
const country = "us";
const sessid = "a123123"
const sesstime = "10"

rp({
    url: 'http://ipinfo.thordata.com',  
    proxy: `http://td-customer-${username}-country-${country}-sessid-${sessid}-sesstime-${sesstime}:${password}@${proxyServer}`,  
})
.then(function(data) {
    console.log(data);  
})
.catch(function(err) {
    console.error(err); 
});
require "uri" 
require 'net/http' 

proxy_host = 't.pr.thordata.net' 
proxy_port = 9999 
proxy_username = 'username'
proxy_pass = 'password'
proxy_country = 'us'
proxy_sessid = 'a123123'
proxy_sesstime = 10
proxy_user = "td-customer-#{proxy_username}-country-#{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
端点生成器
端点生成器