I'm using HttpClient.PostAsync()
and the response is an HttpResponseMessage
. Its Content property is of type HttpContent
which has a CopyToAsync()
method. Unfortunately, this is not cancelable.
Is there a way to get the response copied into a Stream
and pass a CancellationToken
?
I am not stuck with CopyToAsync()
! If there is a workaround, that would be fine. Like read a couple of bytes, check if canceled, continue reading and so on.
The HttpContent.CreateContentReadStreamAsync()
methods looks like it would be a candidate. Unfortunately, it's not available with my selected profile. Also unclear if it would read all data in one go and waste a lot of memory.
Note: I'm using this inside a PCL targeting WP8, Windows Store 8, .NET 4.5, Xamarin.iOS and Xamarin.Android
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…