Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
Example/httpclient.cpp@4:59056313fbfa, 2011-08-16 (annotated)
- Committer:
- yamaguch
- Date:
- Tue Aug 16 12:30:11 2011 +0000
- Revision:
- 4:59056313fbfa
- Child:
- 6:8c44fe7acb82
initial creation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch |
4:59056313fbfa | 1 | #include "mbed.h" |
yamaguch |
4:59056313fbfa | 2 | #include "SimpleSocket.h" |
yamaguch |
4:59056313fbfa | 3 | |
yamaguch |
4:59056313fbfa | 4 | void httpclient() { |
yamaguch |
4:59056313fbfa | 5 | ClientSocket client("www.iana.org", 80); |
yamaguch |
4:59056313fbfa | 6 | char data[] = "GET /domains/example/ HTTP/1.0\r\n\r\n"; |
yamaguch |
4:59056313fbfa | 7 | if (client.connected()) { |
yamaguch |
4:59056313fbfa | 8 | int ret = client.write(data, sizeof(data)); |
yamaguch |
4:59056313fbfa | 9 | int total = 0; |
yamaguch |
4:59056313fbfa | 10 | while (client.connected()) { |
yamaguch |
4:59056313fbfa | 11 | if (client.available()) { |
yamaguch |
4:59056313fbfa | 12 | char buf[129]; |
yamaguch |
4:59056313fbfa | 13 | int len = client.read(buf, sizeof(buf) - 1); |
yamaguch |
4:59056313fbfa | 14 | buf[len] = '\0'; |
yamaguch |
4:59056313fbfa | 15 | printf(buf); |
yamaguch |
4:59056313fbfa | 16 | total += len; |
yamaguch |
4:59056313fbfa | 17 | } |
yamaguch |
4:59056313fbfa | 18 | } |
yamaguch |
4:59056313fbfa | 19 | printf("\n\n*** Total %d ***\n", total); |
yamaguch |
4:59056313fbfa | 20 | } |
yamaguch |
4:59056313fbfa | 21 | } |