// Create an instance of the RestClient var client = new RestClient("https://example.com/api"); // Set the default authorization header client.AddDefaultHeader("Authorization", "Bearer xxxxxxxxxxxxxxx"); // Make a GET request var request = new RestRequest("/users", Method.GET); var response = client.Execute(request);
// Create an instance of the RestClient var client = new RestClient("https://example.com/api"); // Set the default content type header client.AddDefaultHeader("Content-Type", "application/json"); // Make a POST request var request = new RestRequest("/users", Method.POST); request.AddJsonBody(new { name = "John", email = "[email protected]" }); var response = client.Execute(request);In this example, we create an instance of the RestClient and set the default content type header to JSON. Then, we make a POST request to create a new user, including a JSON payload of name and email. The content type header will automatically be included with this request, as well as any future requests made with this RestClient. Overall, the AddDefaultHeader method is a powerful tool for setting common headers that need to be included with every request in a concise and efficient way.