Snip2Code is shutting down.
It has been quite a ride, since 2013 when we launched our first prototype: thanks to the effort of you guys we collected more than 3 million snippets!
We are very proud to help all our users to be more efficient in their jobs, and to be the central point to share programming knowledge for everyone.
Our basic service is free, so we always survived on our own resources to give you Snip2Code.
Unfortunately, we are no more in the financial position to sustain this effort, and therefore we are announcing here our permanent shut down,
which will take place on August 1st, 2020.
Please save your private snippets using our backup function in the settings, here.
IF YOU WANT TO SAVE SNIP2CODE, PLEASE CONSIDER DOING A DONATION!
This will allow us to pay for the servers and the infrastructure. If you want to donate, Contact Us!
by
10
6
3,749
3
Top 1% !
Famous
Nice
Easy-to-find
Specified
MultiPlatform
Popularity: 2986th place
Languagecsharp

kKlient.cs

an experiment in async task-based http methods          C#!!!!
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/662639/kKlient-cs?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.Net; using System.Web; using System.Net.Cache; using System.Threading; using System.Threading.Tasks; public class kKlient { public string Base { get; set; } public RequestCachePolicy CachPol { get; set; } public bool UseDef { get; set; } public ICredentials Credz { get; set; } public WebHeaderCollection Headz { get; set; } public IWebProxy Prxy { get; set; } public kKlient (object[] argz) { new HTTPAction(argz); } public async Task<string> FetchString (string uri, CancellationToken cToken = default (CancellationToken), IProgress<DownloadProgressChangedEventArgs> progress = null) { return await Task.Run(( ) => GetClient(cToken, progress).DownloadStringTaskAsync(uri)); } public async Task<byte[]> FetchData (string uri, CancellationToken cToken = default (CancellationToken), IProgress<DownloadProgressChangedEventArgs> progress = null) { return await Task.Run(( ) => GetClient(cToken, progress).DownloadDataTaskAsync(uri)); } public async Task FetchFile (string uri, string fileName, CancellationToken cToken = default (CancellationToken), IProgress<DownloadProgressChangedEventArgs> progress = null) { await Task.Run(( ) => GetClient(cToken, progress).DownloadFileTaskAsync(uri, fileName)); } internal class HTTPAction : WebClient { public HTTPAction ( ) : base() { } public HTTPAction (string url) : base() { } } private HTTPAction GetClient (CancellationToken cancelToken, IProgress<DownloadProgressChangedEventArgs> progress) { HTTPAction hta = new HTTPAction() { BaseAddress = Base, CachePolicy = CachPol, UseDefaultCredentials = UseDef, Credentials = Credz, Headers = Headz, Proxy = Prxy, }; if (cancelToken != CancellationToken.None) cancelToken.Register(( ) => hta.CancelAsync()); if (progress != null) { hta.DownloadProgressChanged += (sender, args) => progress.Report(args); } return hta; } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus