Authorization with .Net

Tags: #<Tag:0x00007fe314f3e2c0>

Hi All,

I’m trying to get access to the user-genres via the API with .Net, the authorization keeps failing. Can anyone help? The snippet of the code is:-

HttpWebRequest req = DirectCast(WebRequest.Create(“https:musicbrainz/ws/2/recording/ef2ca8c7-ba44-427b-92d9-82161428d24e?inc=genres+user-genres”, HttpWebRequest);
req.Method = “GET”;
req.UserAgent = AppNameVersion;
req.Credentials = New NetworkCredential(Base64Encode(username), Base64Encode(pw))

//Make the call.
response = DirectCast(req.GetResponse(), HttpWebResponse);

It is only when I add the “+user-genres” it fails (error 401).

I have tried with and without Base64 encoding, and the nominal “”, with Basic and Digest modes…

Any pointers appreciated.

Thanks in advance

You do not need to authenticate to get the genre tag.
You need to provide a user agent, this is for rate limiting and so they can contact you if there are problems with your app.

Looking at the .net api documentation you need to provide it with the real username and password, you do not need to base64 encode this.
The api supports digest authentication and I think the .net api selects the authentication method automatically.

1 Like

That’s not entirely correct, you need credentials if requesting user-genres, user-tags etc., because this returns data for the authenticated user.

But I agree with the base64 encoding part, the documentation of NetworkCredential does not indicate this is needed, and as I understand it the underlying implementation should make sure to use username and password as expected by the authenticationm mechanism used in the request .


I have tried it with and without the Base64 encoding - always error 401.

I have looked here, stackoverflow, github, codeproject… for a coding example of authorised access, but without luck.

If anyone has a .net coding example that would be very helpful.

I have discovered bugs in the NetworkCredential() function which prevented it from working.

All good now. :slight_smile:

1 Like

Great. Can you share with us what finally worked?

I found this on SO:-

1 Like

Hi all, I am having trouble with submitting “user-genre” (tag) via the API. It rejects the submission with status 401 (Unauthorized) - the url is:-

I am using the same http authorisation digest that works for GET’ing “user-genre”

I am setting the headers:-

useragent: PoQStacker/ )
contenttype: application/xml; charset=utf-8
contentlength: (content.length)

I am setting the content to:-

<metadata xmlns=""><recording-list><recording id="ef2ca8c7-ba44-427b-92d9-82161428d24e"><user-tag-list><user-tag vote="downvote"><name>swing</name></user-tag></user-tag-list></recording></recording-list></metadata>

Can anyone assist?

Thanks in advance