title: Http POST using Task.FromAsync with async request and async response
body: <p>I have to send an async POST to a web service and I want to send/retrieve the data asynchronously.</p>
  
  <p>I also need to send the request but only wait a maximum of 1500 ms waiting for a response.  If I don't get a response, the program should continue on (this is a service making an external web service call).  I want to offload these service calls to IOCP's instead of blocking for a long time and waiting for them to return.  I only want to block for 1500 ms total.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code> var httpRequest = (HttpWebRequest)WebRequest.Create(@"urltoPostTo");
  
              httpRequest.Method = "POST";
              byte[] data = Encoding.ASCII.GetBytes("test-post");
              httpRequest.ContentLength = data.Length;
              var asyncTask = Task.Factory.FromAsync&lt;Stream&gt;(httpRequest.BeginGetRequestStream, httpRequest.EndGetRequestStream, httpRequest)
                  .ContinueWith(response =&gt;
                  {
                      var localStream = response.Result;
                      if (localStream != null)
                      {
                          localStream.Write(data, 0, data.Length);
                          localStream.Close();
                      }
                  });  //how do I do the continuation for BeginGetResponse and EndGetResponse from here?
  </code></pre>
  
  <p>I have a couple of requirements that unfortunately I can't change.</p>
  
  <ol>
  <li>I am using Visual Studio 2010 targeting 4.0</li>
  <li>I cannot use the Async BCL</li>
  <li>I would like to try and use Task.FromAsync</li>
  </ol>