SimpleSocket 1.0 examples
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
Example/httpclient.cpp
- Committer:
- yamaguch
- Date:
- 2011-09-09
- Revision:
- 24:9c7a2e830ef6
- Parent:
- 15:ae9aff693b07
File content as of revision 24:9c7a2e830ef6:
#include "mbed.h" #include "SimpleSocket.h" void httpclient(char *url) { printf("** httpclient, url = %s\n", url); char hostpart[64], host[64], path[128]; int port = 80; sscanf(url, "http://%[^/]%s", hostpart, path); sscanf(hostpart, "%[^:]:%d", host, &port); ClientSocket socket(host, port); if (socket.connected()) { socket.printf("GET %s HTTP/1.0\r\n\r\n", path); while (socket.connected()) { if (socket.available()) { char buf[128]; int len = socket.read(buf, sizeof(buf) - 1); buf[len] = '\0'; printf(buf); } } printf("Done.\n"); } else { printf("Connction failed.\n"); } }