我嘗試使用到從網上下載文件,下面的命令調用-WebRequest的通網址爲腳本參數(PowerShell中)
Invoke-WebRequest $url -OutFile $filePath -Headers $Headers
我有說法,其中包含此網址,並將其作爲參數
傳遞[string]$artifactHttpAddress = $args[2]
目前,它的價值是
http://10.45.48.26/httpAuth/repository/downloadAll/TeamCityTest_Build/529:id/artifacts.zip
所以,當我嘗試調用WebRequest的使用下面的命令
Invoke-WebRequest $artifactHttpAddress -OutFile c:/test.zip -Headers $Headers
它是空的下載zip文件。
,但是當我嘗試這個網址賦值給變量,並調用Web請求
$url = "http://10.45.48.26/httpAuth/repository/downloadAll/TeamCityTest_Build/529:id/artifacts.zip"
Invoke-WebRequest $url -OutFile c:/test.zip -Headers $Headers
它工作正常,下載zip文件,其中有它的一些內容。
我嘗試下面的腳本
Write-Host([string]$url -eq [string]$artifactHttpAddress)
Write-Host([string]$url)
Write-Host([string]$artifactHttpAddress)
它輸出
False
http://10.45.48.26/httpAuth/repository/downloadAll/TeamCityTest_Build/528:id/artifacts.zip
http://10.45.48.26/httpAuth/repository/downloadAll/TeamCityTest_Build/531:id/artifacts.zip
發生了什麼事,爲什麼?
p.s.這個腳本是ScriptBlock
這是我認爲的問題,錯過了網址之間的差異 – bumbeishvili