8.9Getting the Response Cookie

Created on Aug 17, 2026~3 min read

In an HTTP request, if the server sets a Cookie, the response headers will contain one or more Set-Cookie key-value pairs. After the client receives the response, it can obtain the Cookie information by reading these Set-Cookie key-value pairs. The framework provides the following two convenient ways to obtain the Cookie:

1. Using the HttpRemoteResult<TResult> return value type

HttpRemoteResult<TResult> is a generic type specifically designed to encapsulate the response content in the HTTP remote request module. In addition to the commonly used HTTP response information, this type also provides features such as request elapsed time.

cs
// Using the request verb approach (result type is HttpRemoteResult<string>)var result = await httpRemoteService.GetAsync<string>("https://furion.net/");var setCookies = result.SetCookies; // Get the Cookie collection in the response (IList<SetCookieHeaderValue> type)var rawSetCookies = result.RawSetCookies; // Get the Set-Cookie collection from the raw response headers (List<string> type)// The builder approach works the same way (result type is HttpRemoteResult<string>)var result = await httpRemoteService.SendAsync<string>(HttpRequestBuilder.Get("https://furion.net/"));

2. Using the TryGetSetCookies extension method on HttpResponseMessage

The framework also provides the TryGetSetCookies extension method for the HttpResponseMessage and HttpResponseHeaders types, allowing you to conveniently read and parse the Set-Cookie response header information.

cs
var httpResponseMessage = await httpRemoteService.GetAsync("https://furion.net/");httpResponseMessage.TryGetSetCookies(out var setCookies, out var rawSetCookies);// Or get it through the Headers property// httpResponseMessage.Headers.TryGetSetCookies(out var setCookies, out var rawSetCookies);

Through the two methods above, developers can easily obtain and process the Cookie information in the HTTP response.