Created
September 19, 2012 14:02
-
-
Save numa08/3749849 to your computer and use it in GitHub Desktop.
AsyncAccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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