通过HTTPS下载XML

时间:2018-03-05 14:56:22

标签: xml powershell https copy

我尝试从Jenkins HTTPS服务器下载XML文件(Jenkins config.xml历史文件)。我在这里和其他地方搜索过,但仍然找不到让它运转的方法。

$url = "https://<server-path>/configOutput?type=xml&timestamp=2018-02-23_13-09-02"

$file = "d:\file.xml"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3
$wc = New-Object System.Net.WebClient
$wc.Credentials = Get-Credential
$wc.DownloadFile($url, $file)

提供凭据以提示我收到此错误:

Exception calling "DownloadFile" with "2" argument(s): "The underlying connection
was closed: An unexpected error occurred on a receive."
At D:\ps\jenkins-config\get_xml.ps1:7 char:1
+ $wc.DownloadFile($url,$file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

1 个答案:

答案 0 :(得分:0)

我使用Invoke-WebRequest方法:

Invoke-WebRequest -Uri $url -ContentType 'application/xml' -OutFile $file -Credential $(Get-Credential) -Timeout 60

我已经看到“configOutput”用于JobConfigHistory插件的作业历史记录。我从来没有见过它来获取Jenkin的配置文件(JENKINS_HOME中的那个)。如果您正在尝试控制作业的配置,请仔细检查您的网址。