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
Diff: httpclient.cpp
- Revision:
- 39:108499af2b53
diff -r 000000000000 -r 108499af2b53 httpclient.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/httpclient.cpp Wed Jun 06 03:34:16 2012 +0000
@@ -0,0 +1,30 @@
+#include "EthernetNetIf.h"
+#include "SimpleSocket.h"
+
+void httpclient() {
+ EthernetNetIf eth;
+ eth.setup();
+
+ printf("URL => ");
+ char url[128];
+ scanf("%s", 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) {
+ if (socket.available()) {
+ char buf[128] = {};
+ socket.read(buf, sizeof(buf) - 1);
+ printf("%s", buf);
+ }
+ }
+ }
+}
\ No newline at end of file