2015-02-10 48 views
0

代码:旁路列表创建代理失败,如果它包含“*”

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是正则表达式错误,很奇怪。我试图使用正则表达式转义字符,但没有。

任何解决方案?

回答

1

我搞砸,截至至少两次 - 以下然而似乎正确地添加它虽然一次一个:

$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} 
1

寻找at this它规定的第三个参数是一个正则表达式字符串数组 - *.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} 
+0

感谢:

如果你把它改为然而.*.domain.com它的工作原理。没有注意到这个正则表达式的信息。 – majkinetor 2015-02-10 16:38:03