gpt4 book ai didi

PowerShell - 为什么某些请求类型不起作用?

转载 作者:太空宇宙 更新时间:2023-11-03 13:45:31 24 4
gpt4 key购买 nike

这对我来说真的很奇怪.. http 和 https 的看起来很好.. 端口 8080 和 8443 的不..

$ip="1.2.3.4"
$urls = "http://$ip","http://"$ip":8080","https://$ip","https://"$ip":8443"
foreach ($u in $urls)
{
"$u"
}

结果显示:

PS C:\Documents and Settings\user> D:\WORK\ps\test.ps1
Unexpected token 'ip' in expression or statement.
At D:\WORK\ps\test.ps1:2 char:37
+ $rsaurls = "http://$ip","http://"$ip <<<< ":8080","https://$ip","https://"$ip":8443"
+ CategoryInfo : ParserError: (ip:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken

如果我们删除引号..

$ip="1.2.3.4"
$urls = "http://$ip","http://$ip:8080","https://$ip","https://$ip:8443"
foreach ($u in $urls)
{
"$u"
}

And the results show:
PS C:\Documents and Settings\user> D:\WORK\ps\test.ps1
http://1.2.3.4
http://
https://1.2.3.4
https://

我想我需要转义“:”..

我更近了..

$ip="1.2.3.4"
$urls = "http://$ip","http://$ip^:8080","https://$ip","https://$ip^:8443"
foreach ($u in $urls)
{
"$u"
}

结果:

PS C:\Documents and Settings\user> D:\WORK\ps\test.ps1
http://1.2.3.4
http://1.2.3.4^:8080
https://1.2.3.4
https://1.2.3.4^:8443

谢谢!

最佳答案

我相信 PowerShell 将 $ip:8080 解释为范围为“ip”且名称为“8080”的变量。使用大括号来明确变量名:

"https://${ip}:8080"

关于PowerShell - 为什么某些请求类型不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29354040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com