4using System.Net.Http.Headers;
5using System.Security.Cryptography.X509Certificates;
6using System.Threading.Tasks;
28 public override string[]
UriSchemes =>
new string[] {
"http",
"https" };
38 switch (Uri.Scheme.ToLower())
62 public override async Task<ContentBinaryResponse>
PostAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
63 X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs,
64 params KeyValuePair<string, string>[] Headers)
67 using (HttpClient HttpClient =
new HttpClient(Handler,
true)
69 Timeout = TimeSpan.FromMilliseconds(TimeoutMs)
72 using (HttpRequestMessage Request =
new HttpRequestMessage()
74 Method = HttpMethod.Post,
77 if (EncodedData?.Length > 0 || !
string.IsNullOrEmpty(ContentType))
78 Request.Content =
new ByteArrayContent(EncodedData);
82 if (!
string.IsNullOrEmpty(ContentType))
83 Request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(ContentType);
87 HttpResponseMessage Response = await HttpClient.SendAsync(Request);
102 public static async Task<ContentBinaryResponse>
ProcessResponse(HttpResponseMessage Response, Uri Uri)
104 if (!Response.IsSuccessStatusCode)
110 byte[] Bin = await Response.Content.ReadAsByteArrayAsync();
112 string ContentType = Response.Content.Headers.ContentType?.ToString()
const string DefaultContentType
text/plain
Contains information about a binary response to a content request.
Contains information about a response to a content request.
Exception Error
Error response.
Gets resources from the Web (i.e. using HTTP or HTTPS).
static async Task< ContentResponse > ProcessResponse(HttpResponseMessage Response, Uri Uri)
Decodes a response from the web. If the response is a success, the decoded response is returned....
static void PrepareHeaders(HttpRequestMessage Request, KeyValuePair< string, string >[] Headers, HttpClientHandler Handler)
Prepares headers for a HTTP request.
static HttpClientHandler GetClientHandler()
Gets a HTTP Client handler
static Uri CheckUri(Uri Uri, HttpRequestMessage Request)
Checks the URI, if it is suitable for processing, or if it needs to be modified.
Abstract base class for posters.
Posts to resources on the Web (i.e. using HTTP or HTTPS).
override async Task< ContentBinaryResponse > PostAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static async Task< ContentBinaryResponse > ProcessResponse(HttpResponseMessage Response, Uri Uri)
Decodes a response from the web. If the response is a success, the decoded response is returned....
WebPoster()
Posts to resources on the Web (i.e. using HTTP or HTTPS).
override string[] UriSchemes
Supported URI schemes.
override bool CanPost(Uri Uri, out Grade Grade)
If the poster is able to post to a resource, given its URI.