Using this class could not be easier:public static class WebHelper { public static void Get(string url, Action<string> action) { Get(new Uri(url), action); }
public static void Get(Uri uri, Action<string> action) { var request = WebRequest.CreateHttp(uri);
request.BeginGetResponse(i => { var response = request.EndGetResponse(i); var sreader = new StreamReader(response.GetResponseStream()); var result = sreader.ReadToEnd(); action(result); }, null); } }
string u = @"http://bing.com"; WebHelper.Get(u, html => { Debug.WriteLine(html); });
This class can (and will) be expanded for things like posting form values ... I'll update this post if I do any of those updates :-)