@@ -341,24 +341,28 @@ private static bool IsRetriable(int statusCode)
341
341
/// </remarks>
342
342
protected async Task < T > RequestAsync < T > ( string endPoint , HttpMethod method , params object [ ] jsonBody )
343
343
{
344
- var response = await ExecuteOnOneInstanceAsync ( ( ) => CreateRequest ( endPoint , method , jsonBody ) )
345
- . ConfigureAwait ( continueOnCapturedContext : false ) ;
346
- string responseJson =
347
- await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( continueOnCapturedContext : false ) ;
348
- T t = JObject . Parse ( responseJson ) . ToObject < T > ( JsonSerializer . Create ( ) ) ;
349
- return t ;
344
+ using ( var response = await ExecuteOnOneInstanceAsync ( ( ) => CreateRequest ( endPoint , method , jsonBody ) )
345
+ . ConfigureAwait ( continueOnCapturedContext : false ) )
346
+ {
347
+ string responseJson =
348
+ await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( continueOnCapturedContext : false ) ;
349
+ T t = JObject . Parse ( responseJson ) . ToObject < T > ( JsonSerializer . Create ( ) ) ;
350
+ return t ;
351
+ }
350
352
}
351
353
352
354
/// <remarks>
353
355
/// Used for end points that return a json array [ ... ]
354
356
/// </remarks>
355
357
protected async Task < List < T > > RequestListOfAsync < T > ( string endPoint , HttpMethod method , params object [ ] jsonBody )
356
358
{
357
- var response = await ExecuteOnOneInstanceAsync ( ( ) => CreateRequest ( endPoint , method , jsonBody ) )
358
- . ConfigureAwait ( continueOnCapturedContext : false ) ;
359
- return JArray . Parse (
360
- await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( continueOnCapturedContext : false ) )
361
- . ToObject < List < T > > ( JsonSerializer . Create ( ) ) ;
359
+ using ( var response = await ExecuteOnOneInstanceAsync ( ( ) => CreateRequest ( endPoint , method , jsonBody ) )
360
+ . ConfigureAwait ( continueOnCapturedContext : false ) )
361
+ {
362
+ return JArray . Parse (
363
+ await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( continueOnCapturedContext : false ) )
364
+ . ToObject < List < T > > ( JsonSerializer . Create ( ) ) ;
365
+ }
362
366
}
363
367
364
368
private async Task < HttpRequestMessage > CreateRequest ( string endPoint , HttpMethod method , params object [ ] jsonBody )
0 commit comments