如果绕过列表包含“*”,则创建代理会失败

Creating proxy with bypass list fails if it contains "*"

代码:

 New-Object System.Net.WebProxy($Env:http_proxy, $true, @('localhost', '*.domain.com')

失败并出现错误:

 New-Object : Exception calling ".ctor" with "3" argument(s): "parsing "*.domain.com" - Quantifier {x,y} following nothing."
 At line:1 char:6
 + $p = New-Object System.Net.WebProxy($Env:http_proxy, $true, @('*.domain.com', 'l ...

Quantifier {x,y} following nothing 是一个奇怪的正则表达式错误。我尝试使用正则表达式转义字符,但没有。

有什么解决办法吗?

我至少把它搞砸了两次 - 然而,以下内容似乎一次添加一个正确:

$wp = New-Object System.Net.WebProxy($Env:http_proxy, $true)
$wp.BypassArrayList.Add('localhost')
$wp.BypassArrayList.Add('*.domain.com')

输出

Address               :
BypassProxyOnLocal    : True
BypassList            : {localhost, *.domain.com}
Credentials           : 
UseDefaultCredentials : False
BypassArrayList       : {localhost, *.domain.com}

查看 at this 表明第三个参数是正则表达式字符串数组 - *.domain.com 不是有效的正则表达式,因为字符 class 必须在 * 之前.

如果您将其更改为 .*.domain.com,它会起作用,但是:

[PS] > New-Object System.Net.WebProxy($Env:http_proxy, $true, @("localhost.domain.com",".*.domain.com"))


Address               :
BypassProxyOnLocal    : True
BypassList            : {localhost.domain.com, .*.domain.com}
Credentials           :
UseDefaultCredentials : False
BypassArrayList       : {localhost.domain.com, .*.domain.com}