I'm trying to write a program that deletes files from a specific device. The device has a REST API and I can access it from the CLI without any problems.
For example if I write this in the CLI, it works :
$clip="test.mov"
$ClipsURL="http://123.45.67.89/clips"
$ClipToDelete=@{action="delete";clipname=$clip}
Invoke-RestMethod -Uri $ClipsURL -Body $ClipToDelete -Method Post -ContentType "application/x-www-form-urlencoded"
I can play around with the $ClipToDelete parameter (changing the value of $clip) and it works every time.
Now when I put that in a loop (in my main script) it works the first time, and times out next.
foreach($clip in $ListClips) {
$clip="test.mov"
$ClipsURL="http://123.45.67.89/clips"
$ClipToDelete=@{action="delete";clipname=$clip}
Invoke-RestMethod -Uri $ClipsURL -Body $ClipToDelete -Method Post -ContentType "application/x-www-form-urlencoded"
}
While debuging I can clearly see that all the values passed as parameters to Invoke-RestMethod are correct (the URL & Body are correct).
My first impression is that I should probably close the session (if that makes any sense) before trying to Post again.
I tried adding a SessionVariable
parameter to the command but it didnt change a thing
Does anyone already know how to close a web sesion left open (with the new Invoke-RestMethod command) ? Or does anyone think that the issue lies elsewhere ?
Thank you.