Reading the BitBucket API with Authentication for a Private Repository in C#.net -



Reading the BitBucket API with Authentication for a Private Repository in C#.net -

i've been trying few days bitbucket api work me, have come grinding halt when comes getting work private repository authentication (with issues set private, when they're set public , no authentication needed works fine)

code sample follows:

static void main(string[] args) { webproxy prox = new webproxy("proxygoeshere"); prox.credentials = credentialcache.defaultnetworkcredentials; var address = "repositories/userfoo/slugbar/issues/1"; var repcred = new credentialcache(); repcred.add(new uri("https://api.bitbucket.org/"), "basic", new networkcredential("userfoo", "passbar")); webclient client = new webclient(); client.credentials = repcred; client.proxy = prox; client.baseaddress = "https://api.bitbucket.org/1.0/"; client.usedefaultcredentials = false; client.querystring.add("format", "xml"); console.writeline(client.downloadstring(address)); console.readline(); }

many thanks.

i had same problem recently, , found 2 different solutions.

first, vanilla .net httpwebrequest , httpwebresponse: (this came reply here @ stack overflow, unfortunately can't find link anymore)

string url = "https://api.bitbucket.org/1.0/repositories/your_username/your_repo/issues/1"; var request = webrequest.create(url) httpwebrequest; string credentials = convert.tobase64string(asciiencoding.ascii.getbytes("your_username" + ":" + "your_password")); request.headers.add("authorization", "basic " + credentials); using (var response = request.getresponse() httpwebresponse) { var reader = new streamreader(response.getresponsestream()); string json = reader.readtoend(); }

or, if want same less code, can utilize restsharp:

var client = new restclient("https://api.bitbucket.org/1.0/"); client.authenticator = new httpbasicauthenticator("your_username", "your_password"); var request = new restrequest("repositories/your_username/your_repo/issues/1"); restresponse response = client.execute(request); string json = response.content;

by way, decided utilize the httpwebrequest solution own application. i'm writing little tool clone bitbucket repositories (including private ones) local machine. create one single phone call bitbucket api list of repositories. , didn't want include library in project save few lines of code 1 single call.

c# api bitbucket

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -