> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/services/ihttpclientservice/wisej.ai.services.defaulthttpclientservice.md).

# DefaultHttpClientService

Namespace: **Wisej.AI.Services**

Assembly: **Wisej.AI** (3.5.0.0)

Represents a default HTTP client service that provides methods to send HTTP requests and manage default headers.

{% tabs %}
{% tab title="C#" %}

```csharp
public class DefaultHttpClientService : IHttpClientService
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class DefaultHttpClientService
    Inherits IHttpClientService
```

{% endtab %}
{% endtabs %}

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) DefaultHttpClientService()

Initializes a new instance of [DefaultHttpClientService](https://docs.wisej.com/api?q=wisej.ai.services.defaulthttpclientservice).

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) HttpClient

[HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient): Gets the instance of [HttpClient](#httpclient) used by this service.

This property initializes the [HttpClient](#httpclient) if it is not already initialized. A default User-Agent header is added to the client upon initialization.\
This property is thread-safe and locks on the instance to ensure that the [HttpClient](#httpclient) is initialized only once.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Timeout

[TimeSpan](https://docs.microsoft.com/dotnet/api/system.timespan): Gets or sets the timeout in milliseconds.

## Methods

### ![](/files/ptrKjmmRoQB76pvrIqh0) GetAsync(uri)

Sends a GET request to the specified URI.

| Parameter | Type                                                          | Description                               |
| --------- | ------------------------------------------------------------- | ----------------------------------------- |
| **uri**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The URI to which the GET request is sent. |

**Returns:** [Task\<HttpResponseMessage>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task that represents the asynchronous operation. The task result contains the HTTP response message.

This method sends a GET request to the specified *uri* . The method is asynchronous and returns a task that completes when the HTTP response is received.

```csharp

var clientService = new DefaultHttpClientService();
var response = await clientService.GetAsync("https://api.example.com/resource");

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *uri* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) PostAsync(uri, content)

Sends a POST request to the specified URI with the specified content.

| Parameter   | Type                                                                             | Description                                   |
| ----------- | -------------------------------------------------------------------------------- | --------------------------------------------- |
| **uri**     | [String](https://docs.microsoft.com/dotnet/api/system.string)                    | The URI to which the POST request is sent.    |
| **content** | [HttpContent](https://docs.microsoft.com/dotnet/api/system.net.http.httpcontent) | The HTTP content to be sent with the request. |

**Returns:** [Task\<HttpResponseMessage>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task that represents the asynchronous operation. The task result contains the HTTP response message.

This method sends a POST request to the specified *uri* with the provided *content* . The method is asynchronous and returns a task that completes when the HTTP response is received.

```csharp

var clientService = new DefaultHttpClientService();
var content = new StringContent("{ \"name\": \"value\" }", Encoding.UTF8, "application/json");
var response = await clientService.PostAsync("https://api.example.com/resource", content);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *uri* or *content* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) RemoveDefaultHeader(key)

Removes a default header from the [HttpClient](#httpclient).

| Parameter | Type                                                          | Description                          |
| --------- | ------------------------------------------------------------- | ------------------------------------ |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key of the header to be removed. |

This method removes a header from the HTTP client's request headers based on the specified *key* . If the header does not exist, this method does nothing.

```csharp

var clientService = new DefaultHttpClientService();
clientService.RemoveDefaultHeader("Authorization");

```

### ![](/files/ptrKjmmRoQB76pvrIqh0) SendAsync(request)

Sends an HTTP request to the specified URI.

| Parameter   | Type                                                                                           | Description                       |
| ----------- | ---------------------------------------------------------------------------------------------- | --------------------------------- |
| **request** | [HttpRequestMessage](https://docs.microsoft.com/dotnet/api/system.net.http.httprequestmessage) | The HTTP request message to send. |

**Returns:** [Task\<HttpResponseMessage>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task that represents the asynchronous operation. The task result contains the HTTP response message.

This method sends an HTTP request using the provided *request* . The method is asynchronous and returns a task that completes when the HTTP response is received.

```csharp

var clientService = new DefaultHttpClientService();
var request = new HttpRequestMessage(HttpMethod.Put, "https://api.example.com/resource");
var response = await clientService.SendAsync(request);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *request* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) SetDefaultHeader(key, value)

Adds a default header to the [HttpClient](#httpclient).

| Parameter | Type                                                          | Description                          |
| --------- | ------------------------------------------------------------- | ------------------------------------ |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key of the header to be added.   |
| **value** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The value of the header to be added. |

This method adds a default header to the HTTP client's request headers. If a header with the same key already exists, this method adds another entry to the headers collection.

```csharp

var clientService = new DefaultHttpClientService();
clientService.SetDefaultHeader("Authorization", "Bearer token");

```

### ![](/files/ptrKjmmRoQB76pvrIqh0) SetHandler(handler)

Sets a new HTTP handler for the [HttpClient](#httpclient).

| Parameter   | Type                                                                                         | Description                                                                                                                                   |
| ----------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| **handler** | [HttpClientHandler](https://docs.microsoft.com/dotnet/api/system.net.http.httpclienthandler) | The [HttpClientHandler](https://docs.microsoft.com/dotnet/api/system.net.http.httpclienthandler) to be used by the [HttpClient](#httpclient). |

This method replaces the current [HttpClient](#httpclient) with a new instance using the specified *handler* . A default User-Agent header is also added to the new instance.

```csharp

var clientService = new DefaultHttpClientService();
var handler = new HttpClientHandler
{
// Configure handler properties
};
clientService.SetHandler(handler);

```

## Implements

| Name                                                                    | Description                                                                                      |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| [IHttpClientService](/ai/components/api/services/ihttpclientservice.md) | Represents a service for handling HTTP client operations with customizable handlers and headers. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.wisej.com/ai/components/api/services/ihttpclientservice/wisej.ai.services.defaulthttpclientservice.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
