AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="0.9.8.1" />

 DocumentRequest

public class DocumentRequest
Represents the arguments to load a document.
using AngleSharp.Dom; using AngleSharp.Html; using System; using System.Collections.Generic; using System.IO; namespace AngleSharp.Network { public class DocumentRequest { public INode Source { get; set; } public Url Target { get; } public string Referer { get { return GetHeader(HeaderNames.Referer); } set { SetHeader(HeaderNames.Referer, value); } } public HttpMethod Method { get; set; } public Stream Body { get; set; } public string MimeType { get { return GetHeader(HeaderNames.ContentType); } set { SetHeader(HeaderNames.ContentType, value); } } public Dictionary<string, string> Headers { get; } public DocumentRequest(Url target) { if (target == null) throw new ArgumentNullException("target"); Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); Target = target; Method = HttpMethod.Get; Body = Stream.Null; } public static DocumentRequest Get(Url target, INode source = null, string referer = null) { return new DocumentRequest(target) { Method = HttpMethod.Get, Referer = referer, Source = source }; } public static DocumentRequest Post(Url target, Stream body, string type, INode source = null, string referer = null) { if (body == null) throw new ArgumentNullException("body"); if (type == null) throw new ArgumentNullException("type"); return new DocumentRequest(target) { Method = HttpMethod.Post, Body = body, MimeType = type, Referer = referer, Source = source }; } public static DocumentRequest PostAsPlaintext(Url target, IDictionary<string, string> fields) { if (fields == null) throw new ArgumentNullException("fields"); FormDataSet formDataSet = new FormDataSet(); foreach (KeyValuePair<string, string> field in fields) { formDataSet.Append(field.Key, field.Value, InputTypeNames.Text); } return Post(target, formDataSet.AsPlaintext(null), MimeTypeNames.Plain, null, null); } public static DocumentRequest PostAsUrlencoded(Url target, IDictionary<string, string> fields) { if (fields == null) throw new ArgumentNullException("fields"); FormDataSet formDataSet = new FormDataSet(); foreach (KeyValuePair<string, string> field in fields) { formDataSet.Append(field.Key, field.Value, InputTypeNames.Text); } return Post(target, formDataSet.AsUrlEncoded(null), MimeTypeNames.UrlencodedForm, null, null); } private void SetHeader(string name, string value) { Headers[name] = value; } private string GetHeader(string name) { string value = null; Headers.TryGetValue(name, out value); return value; } } }