From b340f792a6daa2c254543e308dd01176a9fdc043 Mon Sep 17 00:00:00 2001 From: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> Date: Fri, 5 Jul 2019 21:30:51 +0200 Subject: [PATCH 1/3] Create source.vb --- .../system.net.http.httpclient/vb/source.vb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 snippets/visualbasic/VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb diff --git a/snippets/visualbasic/VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb b/snippets/visualbasic/VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb new file mode 100644 index 00000000000..2b2b70b152e --- /dev/null +++ b/snippets/visualbasic/VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb @@ -0,0 +1,28 @@ +Imports System +Imports System.IO +Imports System.Net +Imports System.Net.Http +Imports System.Threading.Tasks + +Class HttpClient_Example + ' + ' HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks. + Shared ReadOnly client As HttpClient = New HttpClient() + + Private Shared Async Function Main() As Task + ' Call asynchronous network methods in a try/catch block to handle exceptions. + Try + Dim response As HttpResponseMessage = Await client.GetAsync("http://www.contoso.com/") + response.EnsureSuccessStatusCode() + Dim responseBody As String = Await response.Content.ReadAsStringAsync() + ' Above three lines can be replaced with new helper method below + ' Dim responseBody As String = Await client.GetStringAsync(uri) + + Console.WriteLine(responseBody) + Catch e As HttpRequestException + Console.WriteLine(Environment.NewLine & "Exception Caught!") + Console.WriteLine("Message :{0} ", e.Message) + End Try + End Function + ' +End Class From d708a0b2a76dd66cb1084574949e05e4a038c684 Mon Sep 17 00:00:00 2001 From: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> Date: Fri, 5 Jul 2019 21:31:25 +0200 Subject: [PATCH 2/3] Update source.cs --- .../VS_Snippets_Misc/system.net.http.httpclient/cs/source.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/csharp/VS_Snippets_Misc/system.net.http.httpclient/cs/source.cs b/snippets/csharp/VS_Snippets_Misc/system.net.http.httpclient/cs/source.cs index 60c352dff23..8b4339d00f5 100644 --- a/snippets/csharp/VS_Snippets_Misc/system.net.http.httpclient/cs/source.cs +++ b/snippets/csharp/VS_Snippets_Misc/system.net.http.httpclient/cs/source.cs @@ -9,10 +9,10 @@ class HttpClient_Example // static async Task Main() { - // Create a New HttpClient object and dispose it when done, so the app doesn't leak resources + // Create a New HttpClient object and dispose it when done, so the app doesn't leak resources. using (HttpClient client = new HttpClient()) { - // Call asynchronous network methods in a try/catch block to handle exceptions + // Call asynchronous network methods in a try/catch block to handle exceptions. try { HttpResponseMessage response = await client.GetAsync("http://www.contoso.com/"); From b270e7156e5a9a7503fa5278d3cf543621c4ae7e Mon Sep 17 00:00:00 2001 From: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> Date: Fri, 5 Jul 2019 21:32:03 +0200 Subject: [PATCH 3/3] Update source.vb --- .../VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/visualbasic/VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb b/snippets/visualbasic/VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb index 2b2b70b152e..f583aec23f1 100644 --- a/snippets/visualbasic/VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb +++ b/snippets/visualbasic/VS_Snippets_Misc/system.net.http.httpclient/vb/source.vb @@ -5,7 +5,7 @@ Imports System.Net.Http Imports System.Threading.Tasks Class HttpClient_Example - ' +' ' HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks. Shared ReadOnly client As HttpClient = New HttpClient() @@ -24,5 +24,5 @@ Class HttpClient_Example Console.WriteLine("Message :{0} ", e.Message) End Try End Function - ' +' End Class