6.20HttpRemoteResult<TResult> Return Value

Created on Aug 17, 2026~8 min read

HttpRemoteResult<TResult> is a generic type specifically used for response content in the HTTP remote request module. The generic parameter TResult represents the data type that needs to be converted into in the end. In addition to supporting common HTTP response types such as string, byte[], Stream, HttpResponseMessage, IAsyncEnumerable<T> and IActionResult<T>, it also supports custom types and the framework's built-in VoidContent type. This type encapsulates commonly used functions such as HTTP response information and request duration.

In the HTTP remote request module, all default generic request methods that do not contain the As keyword return the HttpRemoteResult<TResult> type. The following is an example of obtaining a HttpRemoteResult<TResult> type return value in different ways:

cs
// Request verb approachvar httpResult = await httpRemoteService.GetAsync<string>("https://furion.net/");// Builder approachvar httpResult = await httpRemoteService.SendAsync<string>(HttpRequestBuilder.Get("https://furion.net/"));

HttpRemoteResult<TResult> contains the following properties and methods:

  • Properties:

    • ResponseMessage: the response message (HttpResponseMessage type).
    • ContentType: the content type (string type).
    • CharSet: the character set (string type).
    • ContentEncoding: the content encoding (ICollection<string> type).
    • ContentLength: the content size (long type).
    • Server: the raw response header Server (HttpHeaderValueCollection<ProductInfoHeaderValue> type).
    • RawSetCookies: the raw response header Set-Cookie collection (List<string> type).
    • SetCookies: the response Cookie collection (IList<SetCookieHeaderValue> type).
    • StatusCode: the response status code (HttpStatusCode type).
    • IsSuccessStatusCode: whether the request succeeded (bool type).
    • Result: the target data (TResult generic type).
    • RequestDuration: the request duration in milliseconds (long type).
    • Headers: the response headers (HttpResponseHeaders type).
    • ContentHeaders: the response content headers (HttpContentHeaders type).
    • Version: the HTTP version (Version type).
    • HttpClientName: the configured name of the HttpClient instance (string? type).
  • Methods:

    • ToString(): outputs a string with indented, detailed request and response information.

In the latest version, the framework introduced support for deconstruction for the HttpRemoteResult<TResult> type. Deconstruction expressions simplify the object parsing process, making it more convenient to obtain key property values. The following is the sample code:

cs
// Deconstruction expressions are used to extract the required property valuesvar (result, response) = await httpRemoteService.GetAsync<string>("https://furion.net/");   // You can call ThrowIfNull()/OrDefault() to resolve the null reference warningvar (result, response, isSuccess) = await httpRemoteService.GetAsync<string>("https://furion.net/");    // You can call ThrowIfNull()/OrDefault() to resolve the null reference warningvar (result, response, isSuccess, statusCode) = await httpRemoteService.GetAsync<string>("https://furion.net/");    // You can call ThrowIfNull()/OrDefault() to resolve the null reference warning

In these examples, result is of type TResult, response is of type HttpResponseMessage, isSuccess is of type bool, and statusCode is of type HttpStatusCode.

By using deconstruction expressions, not only is code readability improved, but the development process also becomes more efficient. This improvement allows developers to directly access the data they need, reducing the steps of manually obtaining each property value, thereby making the code more concise and intuitive.


Additionally, the HttpRemoteResult<TResult> type also has a built-in ToString() method, which can clearly print out the detailed information of the request headers and response headers in an indented format, as shown below:

cs
Console.WriteLine(httpResult.ToString());   // Or use Console.WriteLine(httpResult);

The terminal console output is as follows:

bash
Request Headers:    User-Agent:      Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0    traceparent:     00-602c9070b85da9bd73fc1eac36fdb3cb-14dded89e0f5266b-00General:    Request URL:               https://furion.net/    Request Method:            GET    Status Code:               200 OK    HTTP Version:              1.1    HTTP Content:    Content Type:    HttpClient Name:    Request Duration (ms):     133.00Response Headers:    Server:             nginx/1.22.1    Date:               Mon, 18 Nov 2024 21:26:06 GMT    Connection:         keep-alive    Vary:               Accept-Encoding    ETag:               "67091697-f32f"    Cache-Control:      max-age=315360000    Accept-Ranges:      bytes    Content-Type:       text/html    Content-Length:     62255    Last-Modified:      Fri, 11 Oct 2024 12:14:15 GMT    Expires:            Thu, 31 Dec 2037 23:55:55 GMT