[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-cn-powershell-daili-shiyong-zhinan":3},{"success":4,"payload":5,"related":73,"errors":166},true,{"id":6,"slug":7,"title":8,"excerpt":9,"body_html":10,"meta_title":11,"meta_description":12,"canonical_url":13,"canonical_override":14,"og_title":15,"og_description":16,"og_image_url":17,"faq_json":18,"key_takeaways":34,"allow_index":4,"noindex_google_only":40,"allow_follow":4,"published_at":41,"updated_at":41,"content_updated_at":42,"featured_image_url":43,"featured_image_alt":44,"card_image_url":45,"reading_time_minutes":46,"author":47,"categories":51,"tags":58,"alternates":59,"locale_paths":68,"views":72},136,"powershell-daili-shiyong-zhinan","PowerShell 代理使用指南：Invoke-WebRequest 与 Invoke-RestMethod 实战","在 PowerShell 中配置 ProxyHat 住宅代理的完整指南，涵盖 Invoke-WebRequest、Invoke-RestMethod、地理定位、粘性会话、重试退避和并发抓取的代码示例与最佳实践。","\u003Ch2>PowerShell 代理入门：为什么你的脚本需要住宅 IP\u003C\u002Fh2>\n\u003Cp>如果你曾在 PowerShell 中用 \u003Ccode>Invoke-WebRequest\u003C\u002Fcode> 抓取 API 或网页，却频繁收到 403 或 429 错误，问题很可能不在你的代码，而在你的 IP 地址。云数据中心 IP 段（Azure、AWS、GCP）被越来越多的反爬系统列入黑名单。对于 Windows 管理员和自动化工程师来说，掌握 PowerShell 代理配置——尤其是住宅代理——是保证脚本可靠运行的关键技能。\u003C\u002Fp>\n\u003Cp>本文将以代码优先的方式，带你从基础参数到生产级并发抓取，全面掌握在 PowerShell 中使用 ProxyHat 代理的方法。所有示例均使用 \u003Ccode>gate.proxyhat.com:8080\u003C\u002Fcode>（HTTP）或 \u003Ccode>gate.proxyhat.com:1080\u003C\u002Fcode>（SOCKS5）作为网关地址。\u003C\u002Fp>\n\n\u003Ch2>技术背景：为什么数据中心 IP 会被封锁\u003C\u002Fh2>\n\u003Cp>现代反爬系统（如 Cloudflare、Akamai、PerimeterX）通过 IP 信誉数据库识别流量来源。数据中心 IP 段在 \u003Ca href=\"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FComputer_Fraud_and_Abuse_Act\" rel=\"noopener noreferrer\">公开的 ASN 注册表\u003C\u002Fa>中被标记为非 ISP 分配，因此天然具有更高的被封锁风险。\u003Ca href=\"\u002Fcn\u002Fproxy\u002Fresidential\">住宅代理\u003C\u002Fa>使用真实 ISP 分配给家庭用户的 IP 地址，请求看起来与普通用户无异，成功率可达 \u003Cstrong>99.9%\u003C\u002Fstrong> 以上。\u003C\u002Fp>\n\n\u003Ctable>\n\u003Cthead>\n\u003Ctr>\u003Cth>代理类型\u003C\u002Fth>\u003Cth>IP 来源\u003C\u002Fth>\u003Cth>典型延迟\u003C\u002Fth>\u003Cth>反爬穿透率\u003C\u002Fth>\u003Cth>适用场景\u003C\u002Fth>\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\u003Ctd>住宅代理\u003C\u002Ftd>\u003Ctd>真实 ISP 用户\u003C\u002Ftd>\u003Ctd>200ms–800ms\u003C\u002Ftd>\u003Ctd>高\u003C\u002Ftd>\u003Ctd>SERP 抓取、价格监控、社媒研究\u003C\u002Ftd>\u003C\u002Ftr>\n\u003Ctr>\u003Ctd>数据中心代理\u003C\u002Ftd>\u003Ctd>云厂商 ASN\u003C\u002Ftd>\u003Ctd>50ms–150ms\u003C\u002Ftd>\u003Ctd>低\u003C\u002Ftd>\u003Ctd>无 IP 限制的内部 API\u003C\u002Ftd>\u003C\u002Ftr>\n\u003Ctr>\u003Ctd>移动代理\u003C\u002Ftd>\u003Ctd>移动运营商\u003C\u002Ftd>\u003Ctd>300ms–1000ms\u003C\u002Ftd>\u003Ctd>极高\u003C\u002Ftd>\u003Ctd>移动端应用模拟、高防目标\u003C\u002Ftd>\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\n\n\u003Cp>ProxyHat 提供全部三种代理类型，网关地址统一为 \u003Ccode>gate.proxyhat.com\u003C\u002Fcode>。你可以根据目标站点的防护级别灵活切换，详见 \u003Ca href=\"\u002Fcn\u002Fpricing\">定价页面\u003C\u002Fa>。\u003C\u002Fp>\n\n\u003Ch2>基础用法：Invoke-WebRequest 代理参数\u003C\u002Fh2>\n\u003Cp>\u003Ca href=\"https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fpowershell\u002Fmodule\u002Fmicrosoft.powershell.utility\u002Finvoke-webrequest?view=powershell-7.6\" rel=\"noopener noreferrer\">Microsoft 官方文档\u003C\u002Fa>显示，\u003Ccode>Invoke-WebRequest\u003C\u002Fcode> 和 \u003Ccode>Invoke-RestMethod\u003C\u002Fcode> 都原生支持 \u003Ccode>-Proxy\u003C\u002Fcode>、\u003Ccode>-ProxyCredential\u003C\u002Fcode> 和 \u003Ccode>-ProxyUseDefaultCredentials\u003C\u002Fcode> 三个参数。以下是最基本的代理请求示例：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode># 交互式输入用户名和密码\n$cred = Get-Credential\n\n$response = Invoke-WebRequest -Uri &apos;https:\u002F\u002Fhttpbin.org\u002Fip&apos; `\n    -Proxy &apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos; `\n    -ProxyCredential $cred\n\n$response.Content\n# 输出示例: { &quot;origin&quot;: &quot;198.55.x.x&quot; }\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>如果你希望使用当前 Windows 登录凭据进行代理认证，可以用 \u003Ccode>-ProxyUseDefaultCredentials\u003C\u002Fcode> 替代 \u003Ccode>-ProxyCredential\u003C\u002Fcode>：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode>$response = Invoke-WebRequest -Uri &apos;https:\u002F\u002Fhttpbin.org\u002Fip&apos; `\n    -Proxy &apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos; `\n    -ProxyUseDefaultCredentials\n\n$response.Content\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>不过对于 ProxyHat 而言，用户名中需要携带地理定位和会话参数，因此 \u003Ccode>-ProxyUseDefaultCredentials\u003C\u002Fcode> 通常不适用——你需要手动构造 \u003Ccode>PSCredential\u003C\u002Fcode> 对象。\u003C\u002Fp>\n\n\u003Ch2>地理定位与粘性会话：在用户名中编码参数\u003C\u002Fh2>\n\u003Cp>ProxyHat 支持在用户名中嵌入地理定位和会话标识。格式为 \u003Ccode>user-country-{ISO代码}-sid-{自定义ID}\u003C\u002Fcode>。在 PowerShell 中，你需要将用户名和密码封装为 \u003Ccode>PSCredential\u003C\u002Fcode> 对象：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode># 地理定位到美国 + 粘性会话\n$user = &apos;user-country-US-sid-abc123&apos;\n$pass = &apos;your_password&apos;\n$securePass = ConvertTo-SecureString $pass -AsPlainText -Force\n$cred = New-Object System.Management.Automation.PSCredential($user, $securePass)\n\n$response = Invoke-WebRequest -Uri &apos;https:\u002F\u002Fhttpbin.org\u002Fip&apos; `\n    -Proxy &apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos; `\n    -ProxyCredential $cred\n\n$response.Content\n# 同一会话 ID 的后续请求将使用同一出口 IP\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>你还可以进一步精确到城市级别：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode># 定位到德国柏林\n$user = &apos;user-country-DE-region-state_of_berlin-city-berlin&apos;\n$pass = &apos;your_password&apos;\n$securePass = ConvertTo-SecureString $pass -AsPlainText -Force\n$cred = New-Object System.Management.Automation.PSCredential($user, $securePass)\n\n$response = Invoke-WebRequest -Uri &apos;https:\u002F\u002Fhttpbin.org\u002Fip&apos; `\n    -Proxy &apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos; `\n    -ProxyCredential $cred\n\n$response.Content\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>可用的国家\u002F城市代码详见 \u003Ca href=\"\u002Fcn\u002Flocations\">ProxyHat 位置页面\u003C\u002Fa>。粘性会话在需要登录状态保持的场景中尤为重要——例如分页抓取需要同一 IP 才能维持服务端 session。\u003C\u002Fp>\n\n\u003Ch3>使用 System.Net.WebProxy 获得更细粒度的控制\u003C\u002Fh3>\n\u003Cp>当你需要直接操作 \u003Ccode>HttpClient\u003C\u002Fcode> 或对代理行为进行更精细的控制时，可以构造 \u003Ccode>System.Net.WebProxy\u003C\u002Fcode> 对象：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode>$proxy = New-Object System.Net.WebProxy(&apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos;)\n\n$user = &apos;user-country-DE-region-state_of_berlin-city-berlin&apos;\n$pass = &apos;your_password&apos;\n$securePass = ConvertTo-SecureString $pass -AsPlainText -Force\n$proxy.Credentials = New-Object System.Management.Automation.PSCredential($user, $securePass)\n\n# 应用到 HttpClientHandler\nAdd-Type -AssemblyName System.Net.Http\n$handler = New-Object System.Net.Http.HttpClientHandler\n$handler.Proxy = $proxy\n$handler.UseProxy = $true\n\n$client = New-Object System.Net.Http.HttpClient($handler)\n$response = $client.GetAsync(&apos;https:\u002F\u002Fhttpbin.org\u002Fip&apos;).Result\n$response.Content.ReadAsStringAsync().Result\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>这种方式在你需要自定义 TLS 设置、连接池或超时时特别有用。\u003C\u002Fp>\n\n\u003Ch2>会话保持：WebRequestSession 管理 Cookies 与 Headers\u003C\u002Fh2>\n\u003Cp>许多 API 和网站依赖 cookies 进行身份验证和状态跟踪。PowerShell 的 \u003Ccode>-SessionVariable\u003C\u002Fcode> 和 \u003Ccode>-WebSession\u003C\u002Fcode> 参数让你可以在多次请求间保持会话状态：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode>$user = &apos;user-country-US-sid-login123&apos;\n$pass = &apos;your_password&apos;\n$securePass = ConvertTo-SecureString $pass -AsPlainText -Force\n$cred = New-Object System.Management.Automation.PSCredential($user, $securePass)\n\n# 第一次请求：创建会话并设置 headers\n$session = $null\n$response = Invoke-WebRequest -Uri &apos;https:\u002F\u002Fhttpbin.org\u002Fheaders&apos; `\n    -Proxy &apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos; `\n    -ProxyCredential $cred `\n    -SessionVariable session `\n    -UserAgent &apos;Mozilla\u002F5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\u002F537.36&apos; `\n    -Headers @{ &apos;X-Custom-Header&apos; = &apos;ProxyHat-Test&apos;; &apos;Accept-Language&apos; = &apos;en-US,en;q=0.9&apos; }\n\nWrite-Host &quot;Cookies received: $($session.Cookies.Count)&quot;\n\n# 后续请求复用 session（cookies 和部分 headers 自动携带）\n$response2 = Invoke-WebRequest -Uri &apos;https:\u002F\u002Fhttpbin.org\u002Fheaders&apos; `\n    -Proxy &apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos; `\n    -ProxyCredential $cred `\n    -WebSession $session\n\n$response2.Content\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>关键点：每次请求都需要传入 \u003Ccode>-Proxy\u003C\u002Fcode> 和 \u003Ccode>-ProxyCredential\u003C\u002Fcode>，因为 \u003Ccode>WebRequestSession\u003C\u002Fcode> 不会自动继承代理设置。如果你需要更换会话 IP，只需修改用户名中的 \u003Ccode>sid-xxx\u003C\u002Fcode> 部分。\u003C\u002Fp>\n\n\u003Ch2>实战：分页 JSON API 抓取与会话轮换\u003C\u002Fh2>\n\u003Cp>这是最常见的 \u003Cstrong>PowerShell 网页抓取\u003C\u002Fstrong>场景之一：分页请求 JSON API，每页轮换会话以分散请求来源，同时加入重试和退避机制。\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode>$baseUser = &apos;user-country-US&apos;\n$pass = &apos;your_password&apos;\n$securePass = ConvertTo-SecureString $pass -AsPlainText -Force\n$allResults = @()\n\nfor ($page = 1; $page -le 20; $page++) {\n    # 每页使用不同的会话 ID，实现 IP 轮换\n    $sessionId = &quot;sess-page$page-$(Get-Random -Maximum 99999)&quot;\n    $user = &quot;$baseUser-sid-$sessionId&quot;\n    $cred = New-Object System.Management.Automation.PSCredential($user, $securePass)\n    \n    try {\n        $response = Invoke-RestMethod -Uri &quot;https:\u002F\u002Fapi.example.com\u002Fitems?page=$page&quot; `\n            -Proxy &apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos; `\n            -ProxyCredential $cred `\n            -MaximumRetryCount 3 `\n            -RetryIntervalSec 5 `\n            -TimeoutSec 30\n        \n        $allResults += $response.data\n        Write-Host &quot;[OK] Page $page: $($response.data.Count) items&quot;\n    } catch {\n        Write-Warning &quot;[FAIL] Page $page failed after retries: $($_.Exception.Message)&quot;\n        # 指数退避：失败后等待更长时间\n        Start-Sleep -Seconds ([math]::Pow(2, $page % 4))\n    }\n    \n    # 请求间间隔 500ms，避免触发速率限制\n    Start-Sleep -Milliseconds 500\n}\n\nWrite-Host &quot;Total items collected: $($allResults.Count)&quot;\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>这段代码的核心策略：\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>会话轮换\u003C\u002Fstrong>：每页生成新的 \u003Ccode>sid-xxx\u003C\u002Fcode>，ProxyHat 会分配不同的出口 IP。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>自动重试\u003C\u002Fstrong>：\u003Ccode>-MaximumRetryCount 3\u003C\u002Fcode> 和 \u003Ccode>-RetryIntervalSec 5\u003C\u002Fcode> 让 PowerShell 在收到 5xx 或 429 时自动重试最多 3 次，每次间隔 5 秒。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>超时控制\u003C\u002Fstrong>：\u003Ccode>-TimeoutSec 30\u003C\u002Fcode> 防止请求无限挂起。\u003C\u002Fli>\n\u003Cli>指数退避：在 \u003Ccode>catch\u003C\u002Fcode> 块中根据页码计算等待时间，避免在目标站点过载时雪上加霜。\u003C\u002Fli>\n\u003C\u002Ful>\n\n\u003Cp>对于 SERP 追踪和电商价格监控等场景，这种模式可以直接复用。更多用例参考 \u003Ca href=\"\u002Fcn\u002Fuse-cases\u002Fserp-tracking\">SERP 追踪用例\u003C\u002Fa>和 \u003Ca href=\"\u002Fcn\u002Fuse-cases\u002Fweb-scraping\">网页抓取用例\u003C\u002Fa>。\u003C\u002Fp>\n\n\u003Ch2>生产级技巧：环境变量、TLS 与并发\u003C\u002Fh2>\n\n\u003Ch3>通过环境变量为子进程设置代理\u003C\u002Fh3>\n\u003Cp>许多命令行工具（如 \u003Ccode>curl\u003C\u002Fcode>、\u003Ccode>git\u003C\u002Fcode>、\u003Ccode>dotnet\u003C\u002Fcode>）遵循 \u003Ccode>HTTP_PROXY\u003C\u002Fcode> 和 \u003Ccode>HTTPS_PROXY\u003C\u002Fcode> 环境变量约定。在 PowerShell 中设置后，所有子进程都会自动继承：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode># 设置环境变量（当前会话有效）\n$env:HTTP_PROXY  = &apos;http:\u002F\u002Fuser-country-US:your_password@gate.proxyhat.com:8080&apos;\n$env:HTTPS_PROXY = &apos;http:\u002F\u002Fuser-country-US:your_password@gate.proxyhat.com:8080&apos;\n\n# 子进程自动使用代理\ncurl.exe -s https:\u002F\u002Fhttpbin.org\u002Fip\n\n# Invoke-WebRequest 也会读取环境变量（当未显式指定 -Proxy 时）\nInvoke-WebRequest -Uri &apos;https:\u002F\u002Fhttpbin.org\u002Fip&apos; | Select-Object -ExpandProperty Content\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>注意：环境变量中明文包含密码，在生产环境中建议使用 \u003Ccode>ConvertTo-SecureString\u003C\u002Fcode> 加密存储，运行时再解密拼装。\u003C\u002Fp>\n\n\u003Ch3>强制 TLS 1.2\u003C\u002Fh3>\n\u003Cp>Windows PowerShell 5.1 默认使用 TLS 1.0，许多现代 API 会拒绝连接。在脚本开头强制设置 TLS 1.2：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode># 强制使用 TLS 1.2（Windows PowerShell 5.1 必需）\n[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\n# PowerShell 7+ 默认使用系统 SChannel 配置，通常无需此行\n# 但显式设置更安全\n[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Ch3>PowerShell 7 并发：ForEach-Object -Parallel\u003C\u002Fh3>\n\u003Cp>PowerShell 7 引入了 \u003Ccode>ForEach-Object -Parallel\u003C\u002Fcode>，可以轻松实现并发请求。配合 ProxyHat 的会话轮换，能显著提升抓取吞吐量：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode># 确保 TLS 1.2\n[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\n$urls = 1..50 | ForEach-Object { &quot;https:\u002F\u002Fapi.example.com\u002Fitems?page=$_&quot; }\n$pass = &apos;your_password&apos;\n\n$results = $urls | ForEach-Object -Parallel {\n    $securePass = ConvertTo-SecureString $using:pass -AsPlainText -Force\n    $sessionId = &quot;sess-$(Get-Random -Maximum 999999)&quot;\n    $user = &quot;user-country-US-sid-$sessionId&quot;\n    $cred = New-Object System.Management.Automation.PSCredential($user, $securePass)\n    \n    try {\n        $response = Invoke-RestMethod -Uri $_ `\n            -Proxy &apos;http:\u002F\u002Fgate.proxyhat.com:8080&apos; `\n            -ProxyCredential $cred `\n            -MaximumRetryCount 3 `\n            -RetryIntervalSec 3 `\n            -TimeoutSec 30\n        \n        [PSCustomObject]@{\n            Url    = $_\n            Status = &apos;OK&apos;\n            Count  = $response.data.Count\n        }\n    } catch {\n        [PSCustomObject]@{\n            Url    = $_\n            Status = &apos;FAIL&apos;\n            Count  = 0\n            Error  = $_.Exception.Message\n        }\n    }\n} -ThrottleLimit 10\n\n$results | Where-Object { $_.Status -eq &apos;OK&apos; } | Measure-Object -Property Count -Sum\n$results | Where-Object { $_.Status -eq &apos;FAIL&apos; } | Format-Table -AutoSize\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>\u003Ccode>-ThrottleLimit 10\u003C\u002Fcode> 表示最多 10 个并发请求。ProxyHat 支持高并发会话，你可以根据目标站点的速率限制调整此值。建议从 10 并发起步，逐步增加并监控成功率。\u003C\u002Fp>\n\n\u003Ch3>SOCKS5 代理示例\u003C\u002Fh3>\n\u003Cp>当目标站点对 HTTP 代理有检测时，可以使用 SOCKS5 协议。PowerShell 7 的 \u003Ccode>Invoke-WebRequest\u003C\u002Fcode> 原生支持 SOCKS5：\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode>$user = &apos;user-country-US-sid-socks123&apos;\n$pass = &apos;your_password&apos;\n$securePass = ConvertTo-SecureString $pass -AsPlainText -Force\n$cred = New-Object System.Management.Automation.PSCredential($user, $securePass)\n\n$response = Invoke-WebRequest -Uri &apos;https:\u002F\u002Fhttpbin.org\u002Fip&apos; `\n    -Proxy &apos;socks5:\u002F\u002Fgate.proxyhat.com:1080&apos; `\n    -ProxyCredential $cred\n\n$response.Content\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Ch2>常见错误与边缘情况\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>密码包含特殊字符：如果密码含 \u003Ccode>@\u003C\u002Fcode>、\u003Ccode>:\u003C\u002Fcode> 等字符，在环境变量 URL 格式中需要 URL 编码。使用 \u003Ccode>PSCredential\u003C\u002Fcode> 方式则无需编码。\u003C\u002Fli>\n\u003Cli>代理认证返回 407：检查用户名格式是否正确，确保没有多余空格。ProxyHat 用户名格式为 \u003Ccode>user-country-{XX}-sid-{ID}\u003C\u002Fcode>。\u003C\u002Fli>\n\u003Cli>会话不一致：如果多次请求返回不同 IP，检查是否每次都使用了相同的 \u003Ccode>sid-xxx\u003C\u002Fcode> 值。会话保持时间通常为 30 分钟，超时后需要重新生成会话 ID。\u003C\u002Fli>\n\u003Cli>PowerShell 5.1 vs 7：5.1 不支持 \u003Ccode>-Parallel\u003C\u002Fcode>，且 TLS 默认版本较低。建议在生产环境使用 PowerShell 7+。\u003C\u002Fli>\n\u003Cli>证书验证失败：某些企业网络中代理可能触发证书问题。可以临时使用 \u003Ccode>-SkipCertificateCheck\u003C\u002Fcode>（PowerShell 7），但生产环境不推荐。\u003C\u002Fli>\n\u003C\u002Ful>\n\n\u003Ch2>ProxyHat 专属配置与 SDK\u003C\u002Fh2>\n\u003Cp>以上所有示例使用的网关地址 \u003Ccode>gate.proxyhat.com:8080\u003C\u002Fcode>（HTTP）和 \u003Ccode>gate.proxyhat.com:1080\u003C\u002Fcode>（SOCKS5）与 ProxyHat SDK 共享同一端点。这意味着你在 PowerShell 脚本中配置的代理参数与在其他语言（Python、Node.js）中使用 ProxyHat SDK 时的行为完全一致。\u003C\u002Fp>\n\u003Cp>更多配置选项和高级功能（如轮换策略、API 密钥管理）请参阅 \u003Ca href=\"https:\u002F\u002Fdocs.proxyhat.com\u002F\" rel=\"noopener noreferrer\">ProxyHat 官方文档\u003C\u002Fa>。\u003C\u002Fp>\n\n\u003Ch2>道德与法律注意事项\u003C\u002Fh2>\n\u003Cp>使用代理进行数据采集时，务必遵守以下原则：\u003C\u002Fp>\n\u003Cul>\n\u003Cli>仅采集公开数据：不要绕过登录墙或付费墙。受密码保护的内容受法律保护。\u003C\u002Fli>\n\u003Cli>遵守 robots.txt：虽然 robots.txt 不具有法律约束力，但它是网站管理员表达意愿的标准方式。\u003C\u002Fli>\n\u003Cli>美国 CFAA：根据 \u003Ca href=\"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FComputer_Fraud_and_Abuse_Act\" rel=\"noopener noreferrer\">《计算机欺诈和滥用法》\u003C\u002Fa>，未经授权访问计算机系统可能构成联邦犯罪。仅采集公开可访问的数据。\u003C\u002Fli>\n\u003Cli>欧盟 GDPR：如果采集的数据涉及欧盟公民的个人数据，需遵守 GDPR 规定，包括数据最小化原则和被遗忘权。\u003C\u002Fli>\n\u003Cli>优先使用官方 API：如果目标平台提供官方 API，应优先使用。API 通常有更稳定的接口、更清晰的速率限制和更完善的法律授权。\u003C\u002Fli>\n\u003Cli>控制请求频率：即使使用代理，也应设置合理的请求间隔，避免对目标服务器造成压力。\u003C\u002Fli>\n\u003C\u002Ful>","PowerShell 代理使用指南：Invoke-WebRequest 与 REST 调用 | ProxyHat","在 PowerShell 中使用 Invoke-WebRequest 和 Invoke-RestMethod 配置 ProxyHat 住宅代理的完整指南，涵盖地理定位、粘性会话、重试退避和并发抓取。","\u002Fcn\u002Fblog\u002Fpowershell-daili-shiyong-zhinan",null,"PowerShell 代理配置指南 | ProxyHat","使用 Invoke-WebRequest 和 Invoke-RestMethod 配置 ProxyHat 住宅代理，实现地理定位、会话保持和并发抓取的完整代码指南。","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fpowershell-daili-shiyong-zhinan-og.webp",[19,22,25,28,31],{"question":20,"answer":21},"什么是 PowerShell 代理？","PowerShell 代理是指在 PowerShell 脚本中通过 Invoke-WebRequest、Invoke-RestMethod 或 System.Net.WebProxy 等 cmdlet 和 .NET 类将 HTTP\u002FHTTPS 请求路由到中间代理服务器的技术。代理服务器替换原始 IP 地址，用于地理定位、IP 轮换和绕过反爬限制。",{"question":23,"answer":24},"为什么 PowerShell 脚本需要使用代理？","当目标 API 或网站封锁数据中心 IP 段（如 Azure、AWS）时，直接从云服务器或企业网络发起的请求会被拒绝。住宅代理使用真实 ISP 分配的 IP，请求看起来来自普通用户，成功率显著提升。此外，代理还支持地理定位和会话轮换，是自动化脚本的必备组件。",{"question":26,"answer":27},"哪种代理类型最适合 PowerShell 自动化脚本？","大多数 Invoke-WebRequest 代理和 Invoke-RestMethod 代理场景推荐使用住宅代理，因为它们能绕过大多数反爬系统。对于无 IP 限制的内部 API 或简单测试，数据中心代理延迟更低（50ms–150ms）。移动代理适合需要模拟移动端流量的高防护目标。ProxyHat 三种类型都支持，可按需切换。",{"question":29,"answer":30},"如何在 PowerShell 代理请求中避免被封锁？","使用会话轮换（每请求更换 session-xxx）、设置合理请求间隔（500ms 以上）、添加 -MaximumRetryCount 自动重试、使用真实 User-Agent 字符串、保持 cookies 会话一致性，以及控制并发数（建议 10 并发起步）。同时遵守目标站点的 robots.txt 和服务条款。",{"question":32,"answer":33},"PowerShell 5.1 和 PowerShell 7 在代理使用上有什么区别？","PowerShell 7 原生支持 SOCKS5 代理和 ForEach-Object -Parallel 并发，TLS 默认配置更安全。5.1 需要手动设置 [Net.ServicePointManager]::SecurityProtocol 为 TLS 1.2，不支持并行和 SOCKS5。建议生产环境使用 PowerShell 7+。",[35,36,37,38,39],"PowerShell的Invoke-WebRequest和Invoke-RestMethod原生支持-Proxy和-ProxyCredential参数，无需额外模块。","通过在用户名中编码参数可实现地理定位和粘性会话，格式为user-country-US-sid-abc123。","使用-SessionVariable和-WebSession参数可在多次请求间保持cookies和headers会话状态。","PowerShell 7的ForEach-Object -Parallel配合-ThrottleLimit可实现高并发网页抓取。","生产环境脚本开头务必强制设置[Net.ServicePointManager]::SecurityProtocol为TLS 1.2。",false,"2026-07-02T10:05:41+00:00","2026-10-04T02:42:19+00:00","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fpowershell-daili-shiyong-zhinan-master.webp","Using Proxies in PowerShell: A Code-First Guide to Invoke-WebRequest & Invoke-RestMethod","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fpowershell-daili-shiyong-zhinan-card.webp",12,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},"ProxyHat Team","proxyhat-team","The ProxyHat editorial team covers proxies, web scraping, and data extraction.",[52],{"id":53,"slug":54,"name":55,"description":14,"meta_title":56,"meta_description":57,"parent_id":14},4,"kaifa-zhinan","开发者指南","开发者指南 | ProxyHat 博客","代码教程和SDK指南，帮助您将代理集成到应用程序中。",[],{"fr":60,"ru":61,"en":62,"pt":63,"es":64,"tr":65,"ja":66,"zh":13,"ko":67,"x-default":62},"\u002Ffr\u002Fblog\u002Futiliser-proxies-powershell-invoke-webrequest","\u002Fru\u002Fblog\u002Fispolzovanie-proksi-v-powershell","\u002Fblog\u002Fusing-proxies-in-powershell","\u002Fpt\u002Fblog\u002Fusar-proxies-no-powershell","\u002Fes\u002Fblog\u002Fusar-proxies-en-powershell-guia","\u002Ftr\u002Fblog\u002Fpowershell-proxy-kullanimi","\u002Fja\u002Fblog\u002Fpowershell-purokushi-gaido","\u002Fko\u002Fblog\u002Fpowershell-proxy-sayong-gaide",{"fr":60,"ru":61,"pl":69,"en":62,"it":70,"pt":63,"es":64,"tr":65,"ja":66,"zh":13,"de":71,"ko":67},"\u002Fpl\u002Fblog\u002Fuzywanie-proxy-w-powershell","\u002Fit\u002Fblog\u002Fusare-proxy-in-powershell","\u002Fde\u002Fblog\u002Fproxys-in-powershell-verwenden",233,[74,108,135,150],{"id":75,"slug":76,"title":77,"excerpt":78,"featured_image_url":79,"featured_image_alt":80,"card_image_url":81,"og_image_url":82,"published_at":83,"updated_at":84,"content_updated_at":85,"reading_time_minutes":86,"is_featured":40,"indexable":4,"views":87,"author":88,"categories":89,"tags":91},210,"ai-agent-daili-peizhi","AI Agent 代理配置：browser-use、Crawl4AI、MCP","运行在云服务器上的智能体从数据中心 IP 出口。本文给出 browser-use、Crawl4AI 和 MCP 服务器当前可用的代理配置，附粘性与轮换的决策表，以及需要避开的成本陷阱。","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fai-agent-daili-peizhi-master.webp","Proxy Setup for AI Agents: browser-use, Crawl4AI and an MCP Server","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fai-agent-daili-peizhi-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fai-agent-daili-peizhi-og.webp","2026-10-24T09:00:00+00:00","2026-10-24T09:00:20+00:00","2026-10-03T09:41:40+00:00",14,39,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},[90],{"id":53,"slug":54,"name":55,"description":14,"meta_title":56,"meta_description":57,"parent_id":14},[92,96,100,104],{"id":93,"slug":94,"name":95},1,"web-scraping","网页抓取",{"id":97,"slug":98,"name":99},2,"residential-proxies","住宅代理",{"id":101,"slug":102,"name":103},9,"python","Python",{"id":105,"slug":106,"name":107},22,"playwright","Playwright",{"id":109,"slug":110,"title":111,"excerpt":112,"featured_image_url":113,"featured_image_alt":114,"card_image_url":115,"og_image_url":116,"published_at":117,"updated_at":118,"content_updated_at":85,"reading_time_minutes":86,"is_featured":40,"indexable":4,"views":119,"author":120,"categories":121,"tags":123},206,"camoufox-zhuzhai-daili-python-zhinan","Camoufox 搭配住宅代理：代码优先的 Python 指南","如何让在 C++ 层打补丁的 Firefox——Camoufox 在住宅代理后运行：当前的 Python API、geoip 为什么需要粘性会话、指纹一致性检查清单，以及何时 Patchright 或 nodriver 更合适。","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcamoufox-zhuzhai-daili-python-zhinan-master.webp","Camoufox with Residential Proxies: A Code-First Python Guide","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcamoufox-zhuzhai-daili-python-zhinan-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcamoufox-zhuzhai-daili-python-zhinan-og.webp","2026-10-13T09:00:00+00:00","2026-10-13T09:00:22+00:00",48,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},[122],{"id":53,"slug":54,"name":55,"description":14,"meta_title":56,"meta_description":57,"parent_id":14},[124,125,126,130,131],{"id":93,"slug":94,"name":95},{"id":97,"slug":98,"name":99},{"id":127,"slug":128,"name":129},6,"anti-detection","反检测",{"id":101,"slug":102,"name":103},{"id":132,"slug":133,"name":134},21,"headless-browser","无头浏览器",{"id":136,"slug":137,"title":138,"excerpt":139,"featured_image_url":140,"featured_image_alt":141,"card_image_url":142,"og_image_url":143,"published_at":144,"updated_at":144,"content_updated_at":145,"reading_time_minutes":46,"is_featured":40,"indexable":4,"views":6,"author":146,"categories":147,"tags":149},176,"got-scraping-nodejs-proxy-guide","Node.js 中的 got-scraping 完整指南：头部生成与住宅代理实战","深入解析 Apify 的 got-scraping 库——从 header-generator 生成连贯浏览器头部、HTTP\u002F2 支持，到通过 ProxyHat 住宅代理实现大规模 Node.js 爬虫。包含可运行代码、重试钩子、并发控制与生产模式最佳实践。","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fgot-scraping-nodejs-proxy-guide-master.webp","got-scraping in Node.js: A Developer's Guide with Residential Proxies","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fgot-scraping-nodejs-proxy-guide-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fgot-scraping-nodejs-proxy-guide-og.webp","2026-08-04T16:05:06+00:00","2026-10-03T08:29:58+00:00",{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},[148],{"id":53,"slug":54,"name":55,"description":14,"meta_title":56,"meta_description":57,"parent_id":14},[],{"id":151,"slug":152,"title":153,"excerpt":154,"featured_image_url":155,"featured_image_alt":156,"card_image_url":157,"og_image_url":158,"published_at":159,"updated_at":159,"content_updated_at":160,"reading_time_minutes":46,"is_featured":40,"indexable":40,"views":161,"author":162,"categories":163,"tags":165},175,"colly-lunhuan-daili-shixian-zhinan","Colly轮换代理完整指南：用Go构建高吞吐爬虫的实战方案","深入讲解如何在Go的Colly框架中实现代理轮换，涵盖RoundRobinProxySwitcher、SetProxyFunc自定义函数、住宅代理地理定位与会话保持、生产级重试与并发控制，以及分布式存储后端等核心模式。","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcolly-lunhuan-daili-shixian-zhinan-master.webp","Rotating Proxies in Colly: A Framework-Idiomatic Guide for Go Developers","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcolly-lunhuan-daili-shixian-zhinan-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcolly-lunhuan-daili-shixian-zhinan-og.webp","2026-08-04T10:05:34+00:00","2026-10-03T08:29:56+00:00",86,{"name":48,"slug":49,"bio":50,"avatar_url":14,"website_url":14,"social_links":14},[164],{"id":53,"slug":54,"name":55,"description":14,"meta_title":56,"meta_description":57,"parent_id":14},[],[]]