与CURL命令等效的Powershell

与CURL命令等效的Powershell,powershell,powershell-3.0,Powershell,Powershell 3.0,下面给出了CURL命令 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 我想使用Invoke RestMethod获得与Powershell等价的东西 $url='https:/

下面给出了CURL命令

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
我想使用Invoke RestMethod获得与Powershell等价的东西

$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

它返回400(错误请求错误)

使用
-infle
参数,尝试以下操作:

$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

使用
-infle
参数,尝试以下操作:

$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
此代码段应该可以解决您的问题。你的问题有多重打字错误和相互矛盾的逻辑

$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
此代码段应该可以解决您的问题。你的问题有多重打字错误和相互矛盾的逻辑

$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
即使使用了你的建议,我也得到了同样的400(错误请求错误)。即使使用了你的建议,我也得到了同样的400(错误请求错误)。