I've been trying to write a simple HTTP client as a Portable Class Library with minimum dependencies, which made me think that I should use System.Net.HttpWebRequest.
I've looked at the documentation, but it shows only GetResponse/GetResponseStream methods, which I don't have in my implementation. I only have BeginGetResponse, BeginGetResponseStream, etc. I've tried using Task.Factory.FromAsync to convert this to a Task, but that only returns a Task, not a Task<HttpWebResponse>.
Is the correct approach here to use a cast, such as the following?
var response = (Task<HttpWebResponse>)Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse);
Or am I missing something?
edit: I don't want to introduce dependencies on additional NuGet packages, since all I need to do is a single HTTP request in one place in a tiny library.
GetResponseAsync. Not sure if that's available in a PCL though. The System.Net.HttpClient NuGet package is probably a better choice than usingHttpWebRequest.System.Net.Http.HttpClient(nuget.org/packages/Microsoft.Net.Http)Microsoft.Net.Httpif it was part of the base class library and not a download? Like it or not Microsoft is delivering more and more class libraries using NuGet.