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 41825db072b..8b6585b7bbe 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 @@ -12,7 +12,7 @@ class HttpClient_Example static async Task Main() { - // 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/"); 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..f583aec23f1 --- /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