I am loading an image with HttpClient.PostAsync() in my Windows Phone 8 application. The user has the option to cancel this download using the user interface button.
To cancel a POST request, I set a CancellationToken . But that does not work. After the cancellation request, I see that the download is happening in my proxy, and it is obvious that the request was ignored. My code is:
using (var content = new MultipartFormDataContent()) { var file = new StreamContent(stream); file .Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { FileName = "filename.jpg", }; file.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg"); content.Add(file); await httpclient.PostAsync(new Uri("myurl", UriKind.Absolute), content, cancellationToken); }
Also note that for CancellationToken I have a CancellationTokenSource . After the user clicks the Cancel button, tokensource.Cancel() called. In addition, the images in my test folder range from 1 to 2 MB (not so much).
So, is there a way to cancel an HttpClient POST request?
source share