user3772119
user3772119

Reputation: 494

uploading empty file in Powershell?

I'm trying to POST json files in Powershell with this loop:

$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
}

However the output I'm getting from the server, specifically: Content-Length: 52 indicates that Powershell is trying to literally upload the file name, not the contents (the file is 250+ bytes). How do I fix this so that Powershell knows to upload the actual contents (this is a JSON file)?

Upvotes: 1

Views: 206

Answers (1)

DeanOC
DeanOC

Reputation: 7282

OP solved their own problem as follows:

Fixed it. I needed to add the -ContentType application/json tag to my POST line:

Invoke-WebRequest -Uri https://testWebsite.com/ext/ext/ext -ContentType application/json -Method POST -Body $tempFile

Upvotes: 1

Related Questions