File tree Expand file tree Collapse file tree 4 files changed +32
-22
lines changed
cpp/VS_Snippets_Remoting/NCLWebClientUserAgent/CPP
csharp/System.Net/WebClient/Overview
visualbasic/VS_Snippets_Remoting/NCLWebClientUserAgent/VB Expand file tree Collapse file tree 4 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ int main()
2525 Console::WriteLine ( s );
2626 data->Close ();
2727 reader->Close ();
28+ delete client;
2829}
2930
3031// </Snippet1>
Original file line number Diff line number Diff line change 55
66public class Test
77{
8- public static void Main ( string [ ] args )
8+ public static void Main ( string [ ] args )
99 {
1010 if ( args == null || args . Length == 0 )
1111 {
12- throw new ApplicationException ( "Specify the URI of the resource to retrieve." ) ;
12+ throw new ApplicationException ( "Specify the URI of the resource to retrieve." ) ;
1313 }
14- WebClient client = new WebClient ( ) ;
14+ using WebClient client = new WebClient ( ) ;
1515
1616 // Add a user agent header in case the
1717 // requested URI contains a query.
1818
19- client . Headers . Add ( "user-agent" , "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" ) ;
19+ client . Headers . Add ( "user-agent" , "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" ) ;
2020
21- Stream data = client . OpenRead ( args [ 0 ] ) ;
22- StreamReader reader = new StreamReader ( data ) ;
23- string s = reader . ReadToEnd ( ) ;
24- Console . WriteLine ( s ) ;
25- data . Close ( ) ;
26- reader . Close ( ) ;
21+ using Stream data = client . OpenRead ( args [ 0 ] ) ;
22+ StreamReader reader = new StreamReader ( data ) ;
23+ string s = reader . ReadToEnd ( ) ;
24+ Console . WriteLine ( s ) ;
25+ data . Close ( ) ;
26+ reader . Close ( ) ;
2727 }
2828}
2929//</Snippet1>
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+
3+ <PropertyGroup >
4+ <OutputType >Exe</OutputType >
5+ <TargetFrameworks >net6.0</TargetFrameworks >
6+ </PropertyGroup >
7+
8+ </Project >
Original file line number Diff line number Diff line change @@ -10,18 +10,19 @@ Public Class Test
1010 If args Is Nothing OrElse args.Length = 0 Then
1111 Throw New ApplicationException( "Specify the URI of the resource to retrieve." )
1212 End If
13- Dim client As New WebClient()
14-
15- ' Add a user agent header in case the
16- ' requested URI contains a query.
17- client.Headers.Add( "user-agent" , "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" )
18-
19- Dim data As Stream = client.OpenRead(args( 0 ))
20- Dim reader As New StreamReader(data)
21- Dim s As String = reader.ReadToEnd()
22- Console.WriteLine(s)
23- data.Close()
24- reader.Close()
13+ Using client As New WebClient()
14+
15+ ' Add a user agent header in case the
16+ ' requested URI contains a query.
17+ client.Headers.Add( "user-agent" , "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" )
18+
19+ Dim data As Stream = client.OpenRead(args( 0 ))
20+ Dim reader As New StreamReader(data)
21+ Dim s As String = reader.ReadToEnd()
22+ Console.WriteLine(s)
23+ data.Close()
24+ reader.Close()
25+ End Using
2526 End Sub
2627End Class
2728'</Snippet1>
You can’t perform that action at this time.
0 commit comments