Shifterと一緒に使用する Postman
Postman はプロキシをファーストクラスでサポートしています。グローバルレベルで Shifter を一度設定すれば、すべてのコレクションがレジデンシャル IP を通じて実行されます。または、本番環境とステージング環境を分けるために環境ごとにスコープを設定することもできます。
クイックスタート
インストール
// Postman desktop > Settings > Proxy. No install required. 基本的な使い方
// Postman desktop > Settings > Proxy:
//
// ☑ Use custom proxy configuration
// Proxy Type: HTTP and HTTPS
// Proxy Server: p.shifter.io
// Proxy Port: 443
// ☑ This proxy requires authentication
// Proxy Auth Username: customer-USERNAME-country-us-sid-123ABC
// Proxy Auth Password: PASSWORD
//
// Every request you send (and every collection run) now routes
// through Shifter's residential pool. 機能
例
Pre-Request Script — 実行ごとの動的スティッキーセッション
各コレクションの実行開始時に新しい sid を生成し、プロキシのユーザー名に注入します。各実行はクリーンなレジデンシャル IP を取得し、実行内のリクエストはその IP を共有します。
// Collection-level Pre-request Script
//
// Runs once at the start of each collection / Newman run.
const sid = pm.variables.replaceIn("{{$randomAlphaNumeric}}").repeat(2).slice(0, 8);
pm.environment.set("shifter_sid", sid);
// Construct the Shifter username with country + sid + ttl
const country = pm.environment.get("country") || "us";
const user = pm.environment.get("shifter_user");
const pass = pm.environment.get("shifter_pass");
const proxyUser = `${user}-country-${country}-sid-${sid}-ttl-300`;
pm.environment.set("proxy_auth_basic",
"Basic " + Buffer.from(`${proxyUser}:${pass}`).toString("base64"));
console.log("Shifter session:", sid, "country:", country);
// Every request in this run can now reference {{proxy_auth_basic}}
// in its Proxy-Authorization header (when using Postman's "Send via
// proxy" override on individual requests). Newman CLI -- スクリプト化されたコレクション実行
Newman は Postman の CLI です。CI / cron 駆動のテスト実行がコレクションを変更せずにレジデンシャル IP を使用できるよう、Shifter を環境変数として注入します。
# Set Shifter as the system proxy for the Newman process
# (Newman picks up HTTP_PROXY / HTTPS_PROXY env vars automatically)
export HTTP_PROXY="customer-USERNAME-country-us-sid-ci-123ABC:PASSWORD@p.shifter.io:443"
export HTTPS_PROXY="$HTTP_PROXY"
export NO_PROXY="localhost,127.0.0.1"
newman run my-collection.postman_collection.json \
--environment production.postman_environment.json \
--reporters cli,json \
--reporter-json-export results.json
# Or scope per-run with a one-liner:
HTTP_PROXY="http://USER:PASS@p.shifter.io:443" \
HTTPS_PROXY="http://USER:PASS@p.shifter.io:443" \
newman run my-collection.postman_collection.json
# In a GitHub Actions step:
- name: Run Postman tests via Shifter
env:
HTTP_PROXY: http://${{ secrets.SHIFTER_USER }}:${{ secrets.SHIFTER_PASS }}@p.shifter.io:443
HTTPS_PROXY: http://${{ secrets.SHIFTER_USER }}:${{ secrets.SHIFTER_PASS }}@p.shifter.io:443
run: newman run collection.json --environment env.json 環境別プロキシ(本番/ステージング)
1つのコレクション内で環境ごとに異なる国を設定します。環境を切り替えると、Postmanは対応するShifterのレジデンシャルプールを使用します。その他の設定変更は不要です。
// Environment: "Production-US"
{
"values": [
{ "key": "shifter_user", "value": "customer-USERNAME", "type": "secret" },
{ "key": "shifter_pass", "value": "PASSWORD", "type": "secret" },
{ "key": "country", "value": "us" },
{ "key": "base_url", "value": "https://example.com" }
]
}
// Environment: "Production-UK"
{
"values": [
{ "key": "shifter_user", "value": "customer-USERNAME", "type": "secret" },
{ "key": "shifter_pass", "value": "PASSWORD", "type": "secret" },
{ "key": "country", "value": "uk" },
{ "key": "base_url", "value": "https://example.co.uk" }
]
}
// Collection-level Pre-request Script (same script in both environments):
const proxy = {
host: "p.shifter.io",
port: 443,
username: `${pm.environment.get("shifter_user")}-country-${pm.environment.get("country")}-sid-${pm.collectionVariables.get("run_id")}`,
password: pm.environment.get("shifter_pass"),
};
pm.environment.set("proxy_url", `http://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`);
console.log(`Routing through Shifter ${pm.environment.get("country")}`); Postman Cloud Agent(ローカルインストール不要)
Postman Cloud Agent はコレクションを Postman のインフラから実行するため、デスクトップのプロキシ設定は反映されません。回避策:Pre-request Script と pm.sendRequest を使用して、すべての送信リクエストを Shifter Web Scraping API 経由でルーティングしてください。
// Cloud Agent doesn't apply your desktop proxy settings,
// so wrap every outbound request in a call to the Shifter
// Web Scraping API from a Pre-request Script.
const targetUrl = pm.request.url.toString();
const country = pm.environment.get("country") || "us";
const apiKey = pm.environment.get("shifter_api_key");
const params = new URLSearchParams({
api_key: apiKey,
url: targetUrl,
country: country,
render_js: "1", // headless browser rendering
});
pm.sendRequest({
url: `https://scrape.shifter.io/v1?${params.toString()}`,
method: "GET",
}, function (err, res) {
if (err) { console.error(err); return; }
pm.environment.set("forwarded_body", res.text());
pm.environment.set("forwarded_status", res.code);
});
// Tests assert against {{forwarded_body}} instead of the raw
// response — same shape as a real proxy hop, served from
// Shifter's residential pool. よくある質問
Shifter と Postman の併用に関するよくある質問。
設定 > プロキシ > 「カスタムプロキシ設定を使用」を選択します。ホストに `p.shifter.io`、ポートに `443` を入力し、「認証が必要」にチェックを入れ、Shifter のユーザー名(国 / sid セレクター付き)とパスワードを入力してください。それ以降、送信するすべてのリクエストは Shifter 経由でルーティングされます。
はい。Newman は標準のHTTP_PROXY およびHTTPS_PROXY 環境変数に対応しています。`newman run` を実行する前にこれらを設定すると、すべてのテストがShifter を経由するようになります。これはCIパイプラインにプロキシを統合する最も簡潔な方法です。
コレクションレベルのPre-request Scriptを使用して新鮮なsidを生成し(例: `pm.variables.replaceIn("{{$randomAlphaNumeric}}")`)、環境変数に保存します。そのsidをプロキシのユーザー名で参照すると、実行中のすべてのリクエストが1つのレジデンシャルIPを共有します。
はい。環境ごとに`country`変数を設定し(us、uk、jp、deなど)、ShifterプロキシURLを構築するPre-request Scriptで参照してください。環境を切り替えるだけでテストが実行される国が変わります。同じコレクションで、他の変更は不要です。
Postman Cloud Agent は Postman のインフラ上で動作するため、デスクトップのプロキシ設定が適用されません。回避策:Pre-request Script 内で pm.sendRequest を使用して Shifter Web Scraping API(scrape.shifter.io/v1?api_key=...&url=...)を呼び出し、レスポンスを環境変数に保存してください。テストはその変数に対してアサーションを行います。
はい。Postman Monitors はPostman Cloud 上で動作し、Cloud Agent と同じ制約に従います。Cloud Agent の例に示されたWeb Scraping API パターンを使用してください。セルフホスト型のモニターの場合は、自社インフラでHTTP_PROXY をShifter に設定してNewman を実行し、結果をアラートスタックにパイプしてください。
でShifterを使い始める Postman
Shifterの2億500万以上のレジデンシャルおよびISPプロキシを通じてAPIのテスト、スクレイピング、監視を行います。Postmanデスクトップのネイティブプロキシサポート、Newman CIインテグレーション、環境ごとの国切り替えに対応しています。