@@ -201,7 +201,7 @@ public static string HeadFromUrl(this string url, string accept = "*/*",
201201 }
202202
203203 public static Task < string > GetStringFromUrlAsync ( this string url , string accept = "*/*" ,
204- Action < HttpWebRequest > requestFilter = null , Action < HttpWebResponse > responseFilter = null )
204+ Action < HttpWebRequest > requestFilter = null , Action < HttpWebResponse > responseFilter = null )
205205 {
206206 return SendStringToUrlAsync ( url , accept : accept , requestFilter : requestFilter , responseFilter : responseFilter ) ;
207207 }
@@ -348,20 +348,24 @@ public static Task<string> SendStringToUrlAsync(this string url, string method =
348348 }
349349
350350 var taskWebRes = webReq . GetResponseAsync ( ) ;
351- return taskWebRes . ContinueWith ( task =>
352- {
353- var webRes = task . Result ;
354- if ( responseFilter != null )
351+ return taskWebRes
352+ . ContinueWith ( task =>
355353 {
356- responseFilter ( ( HttpWebResponse ) webRes ) ;
357- }
354+ if ( task . Exception != null )
355+ throw task . Exception ;
358356
359- using ( var stream = webRes . GetResponseStream ( ) )
360- using ( var reader = new StreamReader ( stream ) )
361- {
362- return reader . ReadToEnd ( ) ;
363- }
364- } , TaskContinuationOptions . NotOnFaulted | TaskContinuationOptions . OnlyOnRanToCompletion ) ;
357+ var webRes = task . Result ;
358+ if ( responseFilter != null )
359+ {
360+ responseFilter ( ( HttpWebResponse ) webRes ) ;
361+ }
362+
363+ using ( var stream = webRes . GetResponseStream ( ) )
364+ using ( var reader = new StreamReader ( stream ) )
365+ {
366+ return reader . ReadToEnd ( ) ;
367+ }
368+ } , TaskContinuationOptions . NotOnCanceled ) ;
365369 }
366370
367371 public static string SendStringToUrl ( this string url , string method = null ,
0 commit comments