1

I am trying to develop a c# application which sends some HttpWebRequest to BitBucket API.
I am trying to access the below URL.

https://bitbucket.org/api/1.0/repositories/MyUserName/MyRepo/changesets

C# Code

string url = "https://bitbucket.org/api/1.0/repositories/MyUserName/MyRepo/changesets";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = new NetworkCredential("MyUserName", "MyPassword");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();  

This gives me 403 error which means credentials are correct but those credentials do not grant the caller permission to access the resource.

I don't know how to fix do this. I guess some configurations must do in bitbucket but have no idea. I am the owner of this repository.

Please advice me.

Joffrey Kern
  • 6,291
  • 3
  • 26
  • 25
New Developer
  • 3,097
  • 10
  • 38
  • 75

2 Answers2

2

Adding header like below solve my issue.

request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes("username:password")));
New Developer
  • 3,097
  • 10
  • 38
  • 75
0

It doesn't mean that credentials are correct.

You cannot use NetworkCredential that way. Please read the only line describing NetworkCredentials

You have to:

Community
  • 1
  • 1
Peuczynski
  • 4,401
  • 1
  • 16
  • 32
  • according to the API it says that https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs#UsetheBitbucketRESTAPIs-Authentication – New Developer Jun 12 '13 at 09:17
  • Did you read the link? Also: http://stackoverflow.com/questions/1702426/httpwebrequest-not-passing-credentials – Peuczynski Jun 12 '13 at 09:22