1 using System;
2 using System.Net.Http;
3 using System.IO;
4
5 int main()
6 {
7 try
8 {
9 HttpClient httpClient(UriReference("https://tools.ietf.org/"), &Console.Out());
10 HttpHeaderCollection responseHeaders;
11 SharedPtr<ByteStream> body;
12 UriReference uri = "/html/rfc2616";
13 HttpStatus status = httpClient.Get(uri, responseHeaders, body);
14 if (status.StatusCode() == statusSuccessOK)
15 {
16 Console.WriteLine("==========================================================");
17 ulong contentLength = responseHeaders.GetContentLength();
18 Console.WriteLine("content length : " + ToString(contentLength));
19 MimeType contentType = responseHeaders.GetContentType();
20 Console.WriteLine("content type : " + contentType.ToString());
21 DateTime date = responseHeaders.GetDate();
22 Console.WriteLine("date : " + date.ToString());
23 if (ToLower(contentType.GetMediaType()->Name()) == "text" && ToLower(contentType.GetSubtype()->Name()) == "html")
24 {
25 StreamReader reader(body);
26 string content = reader.ReadToEnd();
27
28 }
29 else
30 {
31 throw Exception("text/html content type expected");
32 }
33 Console.WriteLine("==========================================================");
34 }
35 else
36 {
37 throw HttpException(status);
38 }
39 }
40 catch (const Exception& ex)
41 {
42 Console.Error() << ex.ToString() << endl();
43 return 1;
44 }
45 return 0;
46 }