Today I got an UnauthorizedAccessException when running the following script in powershell
Invoke-WebRequest -Uri $url ` -UseDefaultCredentials ` -UseBasicParsing ` -Method Post ` -ContentType 'application/json' ` -InFile data.json
There was no logging on the webserver, there was no access-denied message, there was no traffic at all. What happend?
Turns out the problem was the file (data.json) was readonly. So I added the following step to remove the readonly flag.
Set-ItemProperty data.json -name IsReadOnly -value $false
Now my post to the webservice succeeds.