Hi guys.
I am trying to replicate a database using .NET classes (httpWebRequest) instead
of
curl. Unfortunately, the cURL works, but the (assumably) same syntax in .NET
fails
with a 404 "Unauthorized to access or create database" error. Below is my code.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("sourceURL");
request.Method = "POST";
request.ContentType = "application/json";
long ticks = DateTime.UtcNow.Ticks;
string json = "{ \"_id\":\"database_replicate" + ticks + "\",
\"source\":\"sourceURL/database\", \"target\":\"database\",
\"create_target\":true,
\"user_ctx\": { \"roles\": [\"_admin\"] } }";
using (var writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(json);
writer.Close();
}
Then it fails right here, on the response:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
I am replicating to and from localhost. I tried passing in our credentials
(username and password), as request.credentials, but that didn't work either.
Currently the credentials are being passed in the urls.