Pergunta

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.

Foi útil?

Solução

Adding header like below solve my issue.

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

Outras dicas

It doesn't mean that credentials are correct.

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

You have to:

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top