i'm trying to make a app thats lets me query the database from discogs.
According to the Api documentation i can do this with just a token. so i registered and got a user token.
now when i use postman with https://api.discogs.com/database/search?release_title=nevermind&artist=nirvana&per_page=3&page=1&token=<my_user_token>
i receive the json like i would expect.
but when i make a httpclient in c# with the token
public string token = <my_user_token>;
public static HttpClient client { get; set; }
public static async Task InitilizeClient()
{
await GetAccesToken();
}
private static async Task GetAccesToken()
{
client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.BaseAddress = new Uri(@"https://api.discogs.com");
//client.DefaultRequestHeaders.Authorization=new AuthenticationHeaderValue("Discogs", "token="+token);
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization","Discogs token=" + token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
and then use the client like this
public static async Task QueryDataBaseAsync(string query)
{
if (query == null)
{
throw new Exception("query is empty");
}
string url = "";
url = @"https://api.discogs.com/database/search?release_title="+query;
if (client == null)
{
await InitilizeClient();
}
using (HttpResponseMessage response = await client.GetAsync(url))
{
if (response.IsSuccessStatusCode)
{
}
else
{
throw new Exception(response.ReasonPhrase + " \n" + response.RequestMessage.ToString());
}
}
}
then i always get a ReasonPhrase "forbidden","statuscode: 403"
when i put a breakpoint on my HttpResponseMessage response
i can see that under "headers"=>"responsemessage"=>"headers"=>"authorization" it has my token.
what am i doing wrong?
ps, sorry about the bad english, its not my motherlangue
ps2, i'm new at programming so i would appreciate it if you could eli5 what i did wrong