powershell - cmdlet 无法运行,因为 -ContentType 参数不是有效的 Content-Type 标头
问题描述
嗨,我在我的 devops 管道中运行了以下 Powershell cmdlet,该管道正在将工件上传到 sharePoint 库中。到现在为止一切正常,但我在其中一个项目中遇到了错误。不知道我该如何解决这个问题。如果有人知道这里的任何事情。
我的 Powershell 代码>
$fileSize = (Get-Item -LiteralPath $file).length
write-host "*******"
write-host $file
write-host $fileSize
write-host "*******"
$uploadURLObject = GET-UPLOADLINK -clientId $clientId -clientSecret $clientSecret -nameofFile $nameWithoutExtension
$tokenObject = GET-TOKEN -clientId $clientId -clientSecret $clientSecret
$uploadHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$uploadHeaders.Add("Content-Type", "application/zip")
$uploadHeaders.Add("Content-Range", "bytes " + 0 +"-" + ($fileSize-1) + "/" + $fileSize)
$uploadHeaders.Add("Content-Length", $fileSize)
$uploadHeaders.Add("Authorization", "Bearer "+ $tokenObject.access_token)
# $uploadBody = [System.IO.File]::ReadAllBytes($file)
$uploadBody = Get-Content -LiteralPath $file
write-host $uploadBody
$response = Invoke-RestMethod $uploadURLObject.uploadUrl -Method 'PUT' -Headers $uploadHeaders -Body $uploadBody
# $response = Invoke-RestMethod $uploadURLObject.uploadUrl -Method 'PUT' -Headers $uploadHeaders -Infile $file -SkipHeaderValidation
$response | ConvertTo-Json
错误信息
Invoke-RestMethod :无法运行 cmdlet,因为 -ContentType 参数不是有效的 Content-Type 标头。为 -ContentType 指定一个有效的 Content-Type,然后重试。要禁止标头验证,请提供 -SkipHeaderValidation 参数。
更新:我检查了我的 Headers 键和值,似乎没有什么异常。
Key: Content-Type Value: application/zip
Key: Content-Range Value: bytes 0-66704/66705
Key: Content-Length Value: 66705
Key: Authorization Value: Bearer rzoQ6Ls7YoaQGls8MBlPVScBPA...dfd
解决方案
推荐阅读
- node.js - 使用 node.js 和 Heroku 应用程序设置 SDK 时出错?
- c# - 从 3.1.3 升级到 4.2.0 GraphQL 版本
- d3.js - 如何在d3饼图中的切片坐标中绘制点?
- c# - 当玩家不注意时,敌人会跟随玩家。OnBecameInvisible 不起作用
- tmux - 如何在不附加到会话的情况下创建 tmux 窗口?
- ios - 如何修复“无法在当前状态下查找:关机”错误
- react-native - Agora.io 语音通话快速入门无法正常工作
- javascript - 如何在 React 中的函数组件之间传递状态
- java - 我的班级需要使用 .txt 文件返回最长的公共前缀,但它给我一个错误。谁能找到我的问题?
- java - 如何在 git bash 终端中设置多个 java 类路径