Converting HttpClient to RestSharp

If anyone happens on this, it looks like as of V 106.6.10 you can simply add default parameters to the client to save yourself from having to add your Auth token to every request method:

private void InitializeClient()
{
     _client = new RestClient(BASE_URL);           
     _client.DefaultParameters.Add(new Parameter("Authorization",
                string.Format("Bearer " + TOKEN), 
                ParameterType.HttpHeader));
}

This has fixed my problem:

RestClient client = new RestClient("http://place.holder.nl");
RestRequest request = new RestRequest("api/personeel/myID", Method.GET);
request.AddParameter("Authorization", 
string.Format("Bearer " + access_token),
            ParameterType.HttpHeader);
var response = client.Execute(request);

Upon sniffing with Fiddler, i came to the conclusion that RestSharp sends the access_token as Basic, so with a plain Parameter instead of a HttpBasicAuthenticator i could force the token with a Bearer prefix


Try this

 RestClient client = new RestClient("http://place.holder.nl");
 RestRequest request = new RestRequest("api/personeel/myID",Method.Get);
 request.AddParameter("Authorization",$"Bearer {access_token}",ParameterType.HttpHeader);
 request.AddHeader("Accept", "application/json");
 request.RequestFormat = DataFormat.Json;
 var response = client.Execute(request);