在下面的代码中得到400 bad request:
下面的函数用于验证包
function ValidatePackage([String] $MeridiumToken, [String] $PackageName, [String] $DNSURL) {
try {
Write-Host "Package Validation Process Started for - $PackageName...."
$APIVURL = $DNSURL + '/api/v1/core/metadata/import/validatemetadata'
Write-Host $APIVURL
# Encode Type
$EncodeType = "iso-8859-1"
# Dynamic input parameters section
$FilePath = "$($env:SYSTEM_DEFAULTWORKINGDIRECTORY)/Subtract-a-thon/Automation/" + $PackageName
# Request Headers
$VHeaders = @{ 'MeridiumToken' = $MeridiumToken }
# Reading Package
# Write-Host "Reading Package..."
$FileBinary = [System.IO.File]::ReadAllBytes($FilePath)
$Enc = [System.Text.Encoding]::GetEncoding($EncodeType)
$FileEnc = $Enc.GetString($FileBinary)
$CRLF = "`r`n"
$Boundary = [System.Guid]::NewGuid().ToString()
# FileName
$FileName = Split-Path $FilePath -leaf
# Request Body
$VBody = (
"--$Boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"$FileName`"",
"Content-Type: application/octet-stream$CRLF",
$FileEnc,
"--$Boundary--"
) -join $CRLF
# Request Content Type
$VContentType = "multipart/form-data; boundary=`"$Boundary`""
# REST Call
# Write-Host "Validating Package..."
$ValidateResponse = Invoke-RestMethod -Uri $APIVURL -Method Post -Headers $VHeaders -ContentType $VContentType -Body $VBody
$PkgItems = $ValidateResponse | ConvertTo-Json
Write-Host "Package Validation Process Finished for -" $PackageName
if ($PkgItems.StartsWith("{")) {
$PkgItems = "[$PkgItems]"
}
return $PkgItems
}
catch {
Write-Host "An error occurred:"
Write-Host $_.ScriptStackTrace
throw $_
}
}
1条答案
按热度按时间beq87vna1#
这个问题是与包计数语法,由于这一切都是未来空白,纠正计数语法后,它的工作