Skip to content

Instantly share code, notes, and snippets.

@numa08
Created September 19, 2012 14:02
Show Gist options
  • Save numa08/3749849 to your computer and use it in GitHub Desktop.
Save numa08/3749849 to your computer and use it in GitHub Desktop.
AsyncAccess
public class AsyncAccess
{
public IObservable<string> requestHttpGET(string url)
{
var request = WebRequest.Create(url);
return Observable.FromAsyncPattern<WebResponse>(
request.BeginGetResponse, request.EndGetResponse)
.Invoke()
.Select(resp =>
{
using (var stream = resp.GetResponseStream())
using (var st = new StreamReader(stream))
{
return st.ReadToEnd();
}
}).ObserveOnDispatcher()
.Select(content =>
{
return content;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment