/// <summary>
        /// Executes a HTTP GET request against the server and retrieves the HTML content.
        /// </summary>
        /// <param name="client">Client to use for getting the HTML content.</param>
        /// <param name="uri">URI to retrieve from the server.</param>
        /// <returns>Returns the downloaded HTML page.</returns>
        public static async Task <(HttpResponseMessage, IHtmlDocument)> GetHtmlDocumentAsync(this HttpClient client, string uri)
        {
            var response = await client.GetAsync(uri);

            var document = await HtmlDocumentFactory.CreateFromResponseAsync(response);

            return(response, document);
        }
Example #2
0
        /// <summary>
        /// Creates a new page model instance from a received HTTP response.
        /// </summary>
        /// <param name="client">HTTP client that was used to get the response.</param>
        /// <param name="responseMessage">HTTP Response received from the server.</param>
        /// <typeparam name="TPageModel">The page model to create.</typeparam>
        /// <returns>Returns the created page model.</returns>
        public static async Task <TPageModel> CreateFromResponse <TPageModel>(HttpClient client, HttpResponseMessage responseMessage) where TPageModel : PageModel
        {
            var document = await HtmlDocumentFactory.CreateFromResponseAsync(responseMessage);

            return((TPageModel)Activator.CreateInstance(typeof(TPageModel), client, document));
        }