Is there a guaranteed way to cancel a message when using HttpClient? I currently have a PostAsync call that I am trying to cancel using cancelationToken, but it does not seem to actually interrupt / stop the operation. I still see that the image I am uploading is published correctly.
Am I doing something wrong here or is it possible that the HttpClient is not processing the cancel token before loading?
var sc = new StreamContent(uploadFile.Data); content.Add(sc, uploadFile.FieldName, uploadFile.FileName); var request = new HttpRequestMessage { RequestUri = new Uri(ApiImageUrlUpload), Content = content }; request.Headers.TryAddWithoutValidation("User-Agent", _sessionManager.UserAgent); request.Headers.TransferEncodingChunked = true; using(cancellationToken.Register(() => httpClient.CancelPendingRequests())) httpResponse = await HttpClient.PostAsync(new Uri(ApiImageUrlUpload), content, cancellationToken);
source share