0

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);
    }
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Xaxlii
  • 1
  • 1
  • I do not know of any `HttpClient` class that is static and can be called that way. And everything in there looks like it *should* be a instance variable anyway. What is the value of the `HttpClient` property or it's backing field? – Christopher Feb 29 '20 at 16:26
  • is HttpClient a class or a variable? – Smankusors Feb 29 '20 at 16:27

0 Answers0