@aBAeXW~Y| 4649664VCBCXB

HttpClient.` Files from the Internet must often be accessed. This requires more time due to reduced locality. During this time, a program can perform other tasks.`Class, notes.` The .NET Framework provides a HttpClient class that makes downloading files on separate threads easier. It helps simplify syntax.`To start,` we use the async and await keywords. In Main, we start a task and use DownloadPageAsync, an async method, as the target. This method is started—it downloads a web page. `In DownloadPageAsync, we use 3 using-statements. This helps improve system resource usage.`Await: `We use the await keyword twice. We first call GetAsync and then ReadAsStringAsync. And finally we display the result string.`Using `using`Strings `string`A discussion.` The functionality of HttpClient overlaps with WebClient. The syntax of these two types is different. WebClient does not currently support the async and await syntax. `With WebClient, its "Async" method uses an object token. This is more clumsy.`WebClient `webclient`Therefore: `If async and await are used in the program, the HttpClient is preferable—it gains compiler checking and improved syntax.`A summary.` HttpClient provides powerful functionality with better syntax support for newer threading features. It supports the await keyword.`HttpClient enables` threaded downloads of Internet files with better compiler checking and code validation. It requires newer versions of the .NET Framework. `Async, Await `async

123 2P2O; 2P2O.Net.Http; 2P2O.Threading.Tasks2S2D2; { 12$1{ 11Task t2z2wTask(DownloadPageAsync); 11t.2c(); 112%3"Downloading page..."3); 1124.2xLine(); 1} 12Aasync 2fDownloadPageAsync() 1{3 1122Target page. 1132L page2z3"http://en.wikipedia.org/"3;3 1122Use HttpClient. 1132P(3HttpClient3 client2z2wHttpClient()) 112P(HttpResponseMessage response2zawait client.GetAsync(page)) 112P(HttpContent content2zresponse.Content) 11{32'222x the 2L.2'32L 2I2zawait content.2xAs2MAsync();3 2'2225 the 2I.2'32r2I != null &&2'12I.L2Z >= 50)2'{2'12%2I.Sub2L(0, 50)2y3"..."3);2'} 11} 1} } 3 Downloading page... <!DOCTYPE html> <html lang="en" dir="ltr" class="c...3

ZHttpClient