I'm definitely banging my head against Oauth signed requests so am unsure if it's my code, DotNetOpenAuth or Bitbucket.
I'm trying to add a new deploy key as per
https://confluence.atlassian.com/display/BITBUCKET/deploy-keys+Resource
I'm getting a WebException
saying
The request was aborted: The connection was closed unexpectedly.
Am I posting correctly with DotNetOpenAuth? I can't seem to find any good samples?
My code is follows:
var payload = new Dictionary<string, string>
{
{"accountname", username},
{"key", Uri.EscapeDataString(key.PublicKey)}
};
var dataUrl = @"https://api.bitbucket.org/1.0/repositories/{0}/{1}/deploy-keys";
var url = string.Format(dataUrl, username, projectName);
var endpoint = new MessageReceivingEndpoint(url, HttpDeliveryMethods.PostRequest);
var request = _consumer.PrepareAuthorizedRequest(endpoint, authToken, payload);
var payloadItems = from kvp in payload
select kvp.Key + "=" + kvp.Value;
var data = Encoding.UTF8.GetBytes(string.Join("&", payloadItems));
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
string responseString;
using (var response = request.GetResponse())
{
using (var responseStream = new StreamReader(response.GetResponseStream()))
{
responseString = responseStream.ReadToEnd();
}
}
I get the feeling I just need a good sample of a form post using DotNetOpenAuth so apologies if it seems like i'm lazy; my google fu just isn't paying dividends.