我尝试使用PowerShell从Jenkins下载工件,如下所示:
$webClient = new-object System.Net.WebClient
$webClient.Credentials = New-Object System.Net.NetworkCredential ("username", "password")
$url = "http://jenkins/job/jobName/lastSuccessfulBuild/artifact/*zip*/archive.zip"
$localfilename = "C:\Test\archive.zip"
$webClient.DownloadFile($url, $localfilename)
我得到异常:
“带有” 2“参数的调用” DownloadFile“的异常:”远程服务器返回错误:(403)禁止。“ 在C:\ ps2.ps1:20 char:28 + $ webclient.DownloadFile <<<<($ url,$ localfilename)+ CategoryInfo:未指定:(:) [],MethodInvocationException + FullyQualifiedErrorId:DotNetMethodException
如果我尝试使用wget下载工件,它将起作用:
wget --auth-no-challenge --http-user=username --http-password=password http://jenkins/job/jobName/lastSuccessfulBuild/artifact/*zip*/archive.zip
如果我使用不带参数的wget,则会--auth-no-challenge
出现相同的错误- Forbidden
。
在请求标头中使用此授权非常有效:
# Create web client with authorization header
$webClient = new-object System.Net.WebClient
$credentialAsBytes = [System.Text.Encoding]::ASCII.GetBytes($userName + ":" + $password)
$credentialAsBase64String = [System.Convert]::ToBase64String($credentialAsBytes);
$webClient.Headers[[System.Net.HttpRequestHeader]::Authorization] = "Basic " + $credentialAsBase64String;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句