Reputation: 3305
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.
Upvotes: 1
Views: 3182
Reputation: 3305
Adding header like below solve my issue.
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes("username:password")));
Upvotes: 2
Reputation: 4733
It doesn't mean that credentials are correct.
You cannot use NetworkCredential that way. Please read the only line describing NetworkCredentials
You have to:
Upvotes: 0