Reputation:
The CURL command is given below.
curl -ik -X PUT -H "X-API-Version: 600" -H "Auth:$AUTH" -H "Content-Type: multipart/form-data" -F "filename=@./temp.crl;type=application/pkix-crl" https://$HOST_IP/rest/$ALIASNAME/crl
I wanted to get the Powershell equivalent using Invoke-RestMethod.I tried the below code.
$url='https://'+$hostname+'/rest/+$aliasname+'/crl'
$url
$hdrs=@{}
$hdrs.Add('X-API-Version', '600');
$hdrs.Add('Auth', $Auth);
$hdrs.Add('Content-Type', 'application/json');
$path=get-location
$FileContent = [IO.File]::ReadAllBytes(temp.crl)
$file=@{'filename'=$FileContent}
Invoke-RestMethod -Uri $url -ContentType 'mutlipart/form-data' -Method Put -Headers $hdrs -Body $file
It gives back 400 (Bad Request error)
Upvotes: 0
Views: 2718
Reputation: 19684
This code snippet should resolve your problem. Your question had multiple typos and conflicting logic.
$restArgs = @{
Uri = "https://$hostname/rest/$aliasname/crl"
Headers = @{
'X-API-Version' = 600
Auth = $Auth
}
Method = 'Put'
Body = @{
filename = [IO.File]::ReadAllBytes("$PSScriptRoot\temp.crl")
}
ContentType = 'multipart/form-data'
}
Invoke-RestMethod @restArgs
Upvotes: 1
Reputation: 8889
Use the -InFile
Parameter, Try this:
$FilePath = '/temp.crl' # Make sure the path is correct #
$Headers = @{"X-API-Version" = 600;Auth = $AUTH}
Invoke-RestMethod -Uri "https://$HOST_IP/rest/$ALIASNAME/crl" `
-ContentType 'multipart/form-data' `
-Headers $Headers -Method Put -InFile $FilePath
Upvotes: 1