public static void DoRequest(Action <System.Net.WebClient> actor, RequestParams request) { using (var client = new WebClientTimeouted(request.Caller)) { if (request.HasCredentials) { client.Credentials = request.GetCredentials(); } client.Headers = request.GetHeaders(); client.QueryString = request.GetQueryString(); actor(client); } }
public static T DoRequest <T>(Func <System.Net.WebClient, T> actor, RequestParams request) { using (var client = new WebClientTimeouted(request.Caller)) { if (request.HasCredentials) { client.Credentials = request.GetCredentials(); } client.Headers = request.GetHeaders(); client.QueryString = request.GetQueryString(); return(actor(client)); } }
public static Task DoRequest(Func <System.Net.WebClient, Task> actor, RequestParams request) { var client = new WebClientTimeouted(request.Caller); if (request.HasCredentials) { client.Credentials = request.GetCredentials(); } client.Headers = request.GetHeaders(); client.QueryString = request.GetQueryString(); return(actor(client).ContinueWith((antecedent) => { client.Dispose(); return antecedent; })); }