| 20 | using namespace dlib; |
| 21 | |
| 22 | int main() |
| 23 | { |
| 24 | try |
| 25 | { |
| 26 | // Connect to Google's web server which listens on port 80. If this |
| 27 | // fails it will throw a dlib::socket_error exception. |
| 28 | iosockstream stream("www.google.com:80"); |
| 29 | |
| 30 | // At this point, we can use stream the same way we would use any other |
| 31 | // C++ iostream object. So to test it out, let's make a HTTP GET request |
| 32 | // for the main Google page. |
| 33 | stream << "GET / HTTP/1.0\r\n\r\n"; |
| 34 | |
| 35 | // Here we print each character we get back one at a time. |
| 36 | while (stream.peek() != EOF) |
| 37 | { |
| 38 | cout << (char)stream.get(); |
| 39 | } |
| 40 | } |
| 41 | catch (exception& e) |
| 42 | { |
| 43 | cout << e.what() << endl; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | |