集成

将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.

功能特性

Postman 桌面版原生代理支持——设置 > 代理,无需扩展
Newman CLI 支持 HTTP_PROXY / HTTPS_PROXY 环境变量,适用于无头 CI 运行
预请求脚本可为每次运行生成粘性会话、参数化国家,并为每个请求添加请求头
通过每个环境的国家变量在 195+ 个国家进行地理定向
通过 Web Scraping API + sendRequest 模式兼容 Postman Cloud Agent
在同一 Shifter 网关上支持 HTTP、HTTPS 和 SOCKS5 协议

示例

预请求脚本——每次运行动态生成粘性会话

在每次集合运行开始时生成新的 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 工具。将 Shifter 作为环境变量注入,使 CI / 定时任务驱动的测试运行通过住宅 IP,无需修改集合配置。

# 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

按环境配置代理(生产 / 预发布)

同一集合中为不同环境指定不同国家。切换环境后,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 的基础设施上运行集合——不遵循桌面代理设置。解决方案:通过预请求脚本和 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 路由。

立即开始

开始将Shifter与以下工具配合使用 Postman

通过 Shifter 的 205M+ 住宅和 ISP 代理测试、抓取和监控 API。支持 Postman 桌面端原生代理、Newman CI 集成以及按环境切换国家。

免费试用 Shifter几分钟内完成设置,随时可取消。