1. Bitbucket Website
  2. Public Issue Tracker
  3. master

Issues

Issue #3952 resolved

c# .NET 401 Unauthorized

moander
created an issue

This workds just fine:

{{{ curl -k --user myUsername:myPassword https://api.bitbucket.org/1.0/user/repositories/?format=xml }}}

Same user/pass and uri from .NET fails:

{{{ WebRequest request = WebRequest.Create("https://api.bitbucket.org/1.0/user/repositories/?format=xml"); request.Credentials = new NetworkCredential("myUsername", "myPassword"); WebResponse response = request.GetResponse(); }}}

WebException: The remote server returned an error: (401) Unauthorized.

Comments (4)

  1. Dylan Etkin

    Hi Morten,

    I am not sure about the framework you are using but with curl you are using basic auth. Do you need to tell you .Net web request to use basic?

    As you point out the endpoint is working just fine. I am not sure we are really qualified to help debug .Net code.

    Cheers,

    Dylan

  2. ondravondra

    You must force basic http authentication:

    string authInfo = user + ":" + password; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); request.Headers["Authorization"] = "Basic " + authInfo;

    Remove request.Credentials = ... line completely.

  3. Log in to comment