Skip to content

Commit fd421de

Browse files
author
anjmao
committed
Dispose HttpResponseMessage
1 parent e593533 commit fd421de

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

netcore/Program.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ private static void HandleTest(IApplicationBuilder app)
4545
{
4646
app.Run(async ctx =>
4747
{
48-
var rsp = await _http.GetAsync("/data");
49-
var str = await rsp.Content.ReadAsStringAsync();
48+
using (var rsp = await _http.GetAsync("/data"))
49+
{
50+
var str = await rsp.Content.ReadAsStringAsync();
5051

51-
// deserialize
52-
var obj = JsonConvert.DeserializeObject<Response>(str);
52+
// deserialize
53+
var obj = JsonConvert.DeserializeObject<Response>(str);
5354

54-
// serialize
55-
var json = JsonConvert.SerializeObject(obj);
56-
57-
ctx.Response.ContentType = "application/json";
58-
await ctx.Response.WriteAsync(json);
55+
// serialize
56+
var json = JsonConvert.SerializeObject(obj);
57+
58+
ctx.Response.ContentType = "application/json";
59+
await ctx.Response.WriteAsync(json);
60+
}
5961
});
6062
}
6163

0 commit comments

Comments
 (0)