【发布时间】:2016-12-02 16:44:52
【问题描述】:
我正在尝试使用以下命令从网络下载文件
Invoke-WebRequest $url -OutFile $filePath -Headers $Headers
我有参数,其中包含这个 url,它作为参数传递
[string]$artifactHttpAddress = $args[2]
目前它的值为
http://10.45.48.26/httpAuth/repository/downloadAll/TeamCityTest_Build/529:id/artifacts.zip
所以,当我尝试使用以下命令调用 WebRequestInvoke-WebRequest $artifactHttpAddress -OutFile c:/test.zip -Headers $Headers
它正在下载空的 zip 文件。
但是当我尝试将此 url 分配给变量并调用 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
发生了什么,为什么?
附言这个脚本在ScriptBlock
【问题讨论】:
标签: powershell