132
|
1
|
|
2 private import tango.io.Console;
|
|
3
|
|
4 private import tango.net.http.HttpClient,
|
|
5 tango.net.http.HttpHeaders;
|
|
6
|
|
7 /*******************************************************************************
|
|
8
|
|
9 Shows how to use HttpClient to retrieve content from the D website
|
|
10
|
|
11 *******************************************************************************/
|
|
12
|
|
13 void main()
|
|
14 {
|
|
15 auto client = new HttpClient (HttpClient.Get, "http://www.digitalmars.com/d/intro.html");
|
|
16
|
|
17 // open the client and get the input stream
|
|
18 auto input = client.open;
|
|
19 scope (exit)
|
|
20 client.close;
|
|
21
|
|
22 // display returned content on console
|
|
23 if (client.isResponseOK)
|
|
24 Cout.stream.copy (input);
|
|
25 else
|
|
26 Cout ("failed to return the D home page");
|
|
27
|
|
28 // flush the console
|
|
29 Cout.newline;
|
|
30 }
|