title: http client cancel request in windows 8.1
body: <p>I am working on a Windows Phone 8.1 project. There are two versions of http client in Windows 8.1  - <code>system.net.http</code> and <code>windows.web.http</code>. Microsoft recommends using the later. </p>
  
  <p>So, I decided to go with it. But I can't find a way to cancel the web request started with <code>windows.web.http.httpclient</code>. In <code>system.net.http.httpclient</code> there is a <a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.cancelpendingrequests%28v=vs.118%29.aspx"><code>CancelPendingRequests</code></a> method but no similar methods exist for the later option. </p>
  
  <p>So, is it possible to cancel the web request and if so how?</p>
  
  <p>Sample Code:</p>
  
  <p>Consider a <code>Http Get</code> request google as follows.
  I would like to cancel it before its completion if the user wishes so.</p>
  
  <pre><code>// Windows Phone 8.1 project (not silverlight)
  public sealed partial class MainPage : Page
  {
      Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient();
  
      public MainPage()
      {
          this.InitializeComponent();
  
          this.NavigationCacheMode = NavigationCacheMode.Required;
  
          Windows.Phone.UI.Input.HardwareButtons.BackPressed += (s, e) =&gt;
          {
             CancelGet();
          }
      }
  
      private void CancelGet()
      {
         // What to put here??
         // tried client.Dispose();
         // but still get request completes successfully
      }
  
      private async void Button_Click(object sender, RoutedEventArgs e)
      {
          string res = await client.GetStringAsync(new Uri("http://www.google.com", UriKind.Absolute));
  
          System.Diagnostics.Debug.WriteLine("result obtained\n" + res);
      }
   }
  </code></pre>
  
  <p>None of the methods of HttpClient support CancellationToken.</p>
  
  <p>Also I tried to call Dispose() on the HttpClient  while the request is ongoing (say GetStringAsync). However still neither any exception is thrown nor the request is cancelled; the GetStringAsync completes as normal and shows the correct result.</p>