Question

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.

Was it helpful?

Solution

Adding header like below solve my issue.

request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes("username:password")));

OTHER TIPS

It doesn't mean that credentials are correct.

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

You have to:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top