1

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)?

2
  • 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 Commented Jun 24, 2014 at 19:37
  • I posted your comment as an answer. Can you accept it? (I don't get any rep points BTW as it is marked community wiki) Commented Jun 24, 2014 at 21:43

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.