1
我试图从Nexus存储库下载最新的神器。如果我给出确切的zip文件名称,它工作正常。当我尝试使用通用URL(REST URI)进行下载时,它会给我401 Unauthorized。我也尝试过Invoke-WebRequest
,WebClient
和Invoke-RestMethod
。PowerShell DownloadFile()不适用于Nexus神器下载
$wc = New-Object System.Net.WebClient
$URL = "http://nexusrepo/nexus/service/local/artifact/maven/redirect?r=my-snapshot&g=my.group.id&a=my.artifact.id&v=1.10.0-SNAPSHOT&c=win32.win32.x86_64&p=zip"
$username = "nexus"
$password = "nexus"
$auth = $username + ":" + $password
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($auth)
$EncodedPassword = [System.Convert]::ToBase64String($Encoded)
$wc.Headers.Add("Accept-Encoding", "gzip,deflate")
$wc.Credentials = New-Object System.Net.NetworkCredential($username, $password)
$wc.Headers.Add("Authorization", "Basic " + $EncodedPassword)
$wc.UseDefaultCredentials = $false
$wc.DownloadFile($URL, "MyApp.zip")
Exception calling "DownloadString" with "1" argument(s): "The remote server returned an error: (401) Unauthorized." At C:\temp\NexusDownloadTest\Nexus-Download.ps1:39 char:1 + $weburl = $wc.DownloadString($URL) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
是否有人可以帮助我在此?
Nexus服务器上的日志显示什么? –
我无法访问Nexus服务器的日志。 –
仍在寻找答案。标题信息一旦被重定向就会消失。任何想法我们可以如何在PowerShell中的重定向URL中再次设置Header信息?如果有人能帮助我,请欣赏它。 –