コード統合
Shifter ゲートウェイは p.shifter.io:443 でプレーンな HTTP(S) と SOCKS5 に対応しています。プロキシ認証をサポートする言語であれば、どの HTTP(S) クライアントでも動作し、SDK は不要です。
ユーザー名にはターゲティングおよびセッションの設定情報がエンコードされており、パスワードはアカウントのパスワードです。フラグの一覧は Gateway & auth を参照してください。
Python
Section titled “Python”最も一般的な選択肢は proxies dict を使う requests です。
import requests
proxy = "customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600:PASSWORD@p.shifter.io:443"proxies = {"http": proxy, "https": proxy}
r = requests.get("https://ipinfo.io/json", proxies=proxies)print(r.text)非同期コードの場合、httpx も同様の方法(httpx.AsyncClient(proxies=proxy))で動作します。
Node.js
Section titled “Node.js”node-fetch(または Node 18 以降に組み込まれている fetch)を https-proxy-agent と組み合わせて使用します。
import fetch from 'node-fetch';import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent( 'customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600:PASSWORD@p.shifter.io:443');
const res = await fetch('https://ipinfo.io/json', { agent });console.log(await res.text());axios、got、undici はいずれも同様のエージェントオプションを受け付けます。
TypeScript
Section titled “TypeScript”Node.js と同じランタイムで、型が付いているだけです。axios を使った例は以下の通りです。
import axios from 'axios';import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent( 'customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600:PASSWORD@p.shifter.io:443');
const { data } = await axios.get<string>('https://ipinfo.io/json', { httpAgent: agent, httpsAgent: agent,});
console.log(data);JavaScript
Section titled “JavaScript”トランスパイラを使わないプレーンな Node CommonJS の例です。
const fetch = require('node-fetch');const { HttpsProxyAgent } = require('https-proxy-agent');
const agent = new HttpsProxyAgent( 'customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600:PASSWORD@p.shifter.io:443');
fetch('https://ipinfo.io/json', { agent }) .then((r) => r.text()) .then(console.log);サードパーティ依存のない標準ライブラリです。
package main
import ( "fmt" "io" "net/http" "net/url")
func main() { proxyURL, _ := url.Parse("customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600:PASSWORD@p.shifter.io:443") client := &http.Client{ Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}, }
resp, _ := client.Get("https://ipinfo.io/json") defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body))}プロキシにベーシック認証を使う reqwest です。
use reqwest::blocking::Client;use reqwest::Proxy;
fn main() -> Result<(), Box<dyn std::error::Error>> { let proxy = Proxy::all("http://p.shifter.io:443")? .basic_auth("customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600", "PASSWORD");
let client = Client::builder().proxy(proxy).build()?; let body = client.get("https://ipinfo.io/json").send()?.text()?; println!("{body}"); Ok(())}組み込みの java.net.http.HttpClient(Java 11 以降)です。
import java.net.*;import java.net.http.*;
public class Main { public static void main(String[] args) throws Exception { HttpClient client = HttpClient.newBuilder() .proxy(ProxySelector.of(new InetSocketAddress("p.shifter.io", 443))) .authenticator(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600", "PASSWORD".toCharArray() ); } }) .build();
HttpRequest req = HttpRequest.newBuilder(URI.create("https://ipinfo.io/json")).build(); HttpResponse<String> res = client.send(req, HttpResponse.BodyHandlers.ofString()); System.out.println(res.body()); }}C#
HttpClientHandler.Proxy を使った HttpClient の例です。
using System.Net;using System.Net.Http;
var handler = new HttpClientHandler{ Proxy = new WebProxy("http://p.shifter.io:443") { Credentials = new NetworkCredential( "customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600", "PASSWORD" ) }, UseProxy = true};
using var client = new HttpClient(handler);var ip = await client.GetStringAsync("https://ipinfo.io/json");Console.WriteLine(ip);proxy リクエストオプションを使う Guzzle です。
<?phprequire 'vendor/autoload.php';
$client = new GuzzleHttp\Client([ 'proxy' => 'customer-USERNAME-country-us-sid-9f3a2b7c-ttl-600:PASSWORD@p.shifter.io:443',]);
$res = $client->get('https://ipinfo.io/json');echo $res->getBody();プレーンな curl バインディング(curl_setopt($ch, CURLOPT_PROXY, '...'))も動作します。
他に必要なものがある場合
Section titled “他に必要なものがある場合”このゲートウェイはプレーンな HTTP/HTTPS/SOCKS プロキシです。クライアントがベーシック認証付きでこれらのいずれかに対応していれば動作します。製品固有のツール(Scrapy、Puppeteer、Playwright、SwitchyOmega、Multilogin)については、Residential Proxies → Integrations を参照してください。