$apit="userid:apitoken"
$serverhost="@host1.com"
$vin="https://${apit}\${serverhost}"
Invoke-WebRequest -Uri $vin -Method POST
错误日志:
Invoke-WebRequest : Cannot bind parameter 'Uri'. Cannot convert value "https://${apit}\${serverhost}" to type "System.Uri". Error:
"Invalid URI: The hostname could not be parsed."
At line:5 char:24
+ Invoke-WebRequest -Uri $vin -Method POST
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId :
CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
答案 0 :(得分:1)
$apit="userid:apitoken"
$serverhost="@host1.com"
$vin="https://" + $apit + $serverhost
Invoke-WebRequest -Uri $vin -Method POST
字符串连接的这种语法是最易读的IMO。你的花括号是不必要的。