I'm hosting a local instance of couchdb via docker at localhost:5984/
.
With a python requests client, I can make admin changes via API like so:
>>> requests.put('http://admin:password@localhost:5984/testdb').json()
{'ok': True}
However, when attempting with Windows HTTP client, couchdb says I'm not an admin user. I'm interpreting this as a failed authentication.
> Invoke-WebRequest -Method PUT http://admin:password@localhost:5984/testdb
Invoke-WebRequest : {"error":"unauthorized","reason":"You are not a server admin."}
At line:1 char:1
+ Invoke-WebRequest -Method PUT http://admin:password@localhost:5984/te ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Does Invoke-WebRequest
have some kind of behavior preventing ability to embed credentials within the URL scheme?
Inserting the username and password in the URL as you are doing is not supported by Invoke-WebRequest
. Instead, you have two options:
Get-Credential
to build a username/password credential and then pass it to Invoke-WebRequest
using the -Credential
parameter. For instance:$cred = Get-Credential "admin" # this will prompt you for the password
Invoke-WebRequest -Credential $cred -Method PUT http://localhost:5984/testdb
-Headers
parameter. For instance:$auth = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("admin:password"))
Invoke-WebRequest -Headers @{Authorization = "Basic " + $auth} -Method PUT http://localhost:5984/testdb