在Powershell中上载空文件?
我正在尝试使用以下循环在Powershell中发布json文件:在Powershell中上载空文件?,powershell,Powershell,我正在尝试使用以下循环在Powershell中发布json文件: $negativeTests = Get-ChildItem "C:\Users\ME\folder\folder\folder\" #Write-Host $negativeTests; for ($i = 0; $i -lt $negativeTests.Count; $i++) { $tempFile = Get-Content $negativeTests[$i].PSPath Invoke-WebRequ
$negativeTests = Get-ChildItem "C:\Users\ME\folder\folder\folder\"
#Write-Host $negativeTests;
for ($i = 0; $i -lt $negativeTests.Count; $i++) {
$tempFile = Get-Content $negativeTests[$i].PSPath
Invoke-WebRequest -Uri https://testWebsite.com/ext/ext/ext -Method POST -Body $tempFile
}
但是,我从服务器获得的输出,特别是:
Content-Length:52
表明Powershell正在尝试按字面意思上载文件名,而不是内容(文件的长度超过250字节)。如何修复此问题,以便Powershell知道如何上载实际内容(这是一个JSON文件)?OP解决了他们自己的问题,如下所示:
修好了。我需要将-ContentType应用程序/json标记添加到我的帖子行:
Invoke-WebRequest -Uri https://testWebsite.com/ext/ext/ext -ContentType application/json -Method POST -Body $tempFile
修好了。我需要将
-ContentType应用程序/json
标记添加到我的帖子行:调用WebRequest-Urihttps://testWebsite.com/ext/ext/ext -ContentType应用程序/json-Method POST-Body$tempFile
。你能接受吗?(顺便说一句,我没有获得任何代表积分,因为它被标记为community wiki)