I'm currently writing an api wrapper. To be able to send api request you need an authorization token but the code i currently have doesn't return a value.
public string Token
{
get
{
return HttpClient.Token;
}
set
{
string fix = value;
HttpClient.Token = value;
try
{
GetLocalUser();
}
catch (InvalidTokenException)
{
if(fix != null)
HttpClient.Token = fix;
throw;
}
}
}
Note: it gives me a nullreference exception at HttpClient.Token = value;
Edit forgot to show the token part in my HttpClient Class its a public class
public string Token
{
get
{
if (headers_.TryGetValue("Authorization", out string token))
return token;
else
return null;
}
set
{
if (headers_.ContainsKey("Authorization"))
headers_.Remove("Authorization");
headers_.Add("Authorization", value);
}
}