Esempio n. 1
0
        public static async Task <string> GetYamlText(this Uri uri, CancellationToken ct = default(CancellationToken),
                                                      Action <HttpClient> setup          = null)
        {
            using (var client = DownloaderExtensions.GetHttpClient()) {
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(YamlMimeType));
                client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", YamlMimeAcceptType);
                DownloaderExtensions.HandleSetup(setup, client, uri);

                using (var r = await client.GetAsync(uri, ct).ConfigureAwait(false)) {
                    await r.EnsureSuccessStatusCodeAsync().ConfigureAwait(false);

                    return(await DownloaderExtensions.TryReadStringContent(r).ConfigureAwait(false));
                }
            }
        }
Esempio n. 2
0
        public static async Task <string> PostYaml(object model, Uri uri,
                                                   CancellationToken ct = default(CancellationToken), Action <HttpClient> setup = null)
        {
            DownloaderExtensions.Validator.ValidateObject(model);
            using (var client = new HttpClient()) {
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(YamlMimeType));
                client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", YamlMimeAcceptType);
                DownloaderExtensions.HandleSetup(setup, client, uri);

                using (var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, YamlMimeType)) {
                    using (var r = await client.PostAsync(uri, content, ct).ConfigureAwait(false)) {
                        await r.EnsureSuccessStatusCodeAsync().ConfigureAwait(false);

                        return(await DownloaderExtensions.TryReadStringContent(r).ConfigureAwait(false));
                    }
                }
            }
        }