【发布时间】:2019-05-22 04:10:47
【问题描述】:
我正在尝试将 ssl 证书上传到 f5 REST API,但没有找到任何人使用 powershell 来执行此操作。我已经在这个页面周围设置了使用 curl f5-Dev-central
的调用 webrequestf5 是:BIG-IP 13.1.1 Build 0.0.4 Final
我收到以下错误
Invoke-webrequest : {"code":400,"message":"Chunk byte count 8802 in Content-Range header different from received buffer length 162","originalRequestBody":
这是脚本的一部分:
....
#read the size of the file with the correct encoding
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$file = [IO.File]::ReadAllBytes($pathtofile)
$enc = [System.Text.Encoding]::GetEncoding("iso-8859-1")
$encodedfile = $enc.GetString($file)
#get range of bytes for entire file in start-end/total format
$range = "0-" + ($encodedfile.Length - 1) + "/" + $encodedfile.Length
#create parts for invoke-webrequest call
#create header json
$headers = @{"Content-Range" = $range; Authorization = $basicAuthValue}
$uri = "https://$bigip/mgmt/shared/file-transfer/bulk/uploads/$nameofcert.crt"
$params = @{'command'="install";'name'="$nameofcert";'from-local-file'=$pathtofile}
$json = $params | ConvertTo-Json
#run the invoke
Invoke-webrequest -Method POST -uri $uri -Headers $Headers -Body $json -ContentType 'application/json'
【问题讨论】:
-
您有工作的 Curl 样本吗?乍一看 $encodedfile 看起来有点奇怪。也知道什么是 8802 和 162 长度?
-
8802 是文件的总大小,也就是 $encodedfile.length 不确定该错误中 162 的来源
-
它可能是body json的大小,你能检查一下吗?该脚本是否打算将该文件上传到服务器?
-
curl in powershell 是 invoke-webrequest 的别名 - 所以要使用 CURL 我需要移动到 linux 子系统或专门调用 CURL.exe
-
我的意思是实际的 curl 。您提供的示例和指向 curl 解决方案的链接完全不同。您是否使用了其他 curl 示例?无论如何,如果目标是上传文件,文件字节应该在请求正文中
标签: rest powershell f5