HTTP client

Dependencies:   mbed-rtos mbed

Committer:
lzzcd001
Date:
Wed Feb 18 14:56:26 2015 +0000
Revision:
0:078749d5c10c
HTTP client

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lzzcd001 0:078749d5c10c 1 #include "mbed.h"
lzzcd001 0:078749d5c10c 2 #include "EthernetInterface.h"
lzzcd001 0:078749d5c10c 3
lzzcd001 0:078749d5c10c 4 int main() {
lzzcd001 0:078749d5c10c 5 EthernetInterface eth;
lzzcd001 0:078749d5c10c 6 eth.init(); //Use DHCP
lzzcd001 0:078749d5c10c 7 eth.connect();
lzzcd001 0:078749d5c10c 8 printf("IP Address is %s\n", eth.getIPAddress());
lzzcd001 0:078749d5c10c 9
lzzcd001 0:078749d5c10c 10 TCPSocketConnection sock;
lzzcd001 0:078749d5c10c 11 sock.connect("mbed.org", 80);
lzzcd001 0:078749d5c10c 12
lzzcd001 0:078749d5c10c 13 char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
lzzcd001 0:078749d5c10c 14 sock.send_all(http
lzzcd001 0:078749d5c10c 15 _cmd, sizeof(http_cmd)-1);
lzzcd001 0:078749d5c10c 16
lzzcd001 0:078749d5c10c 17 char buffer[300];
lzzcd001 0:078749d5c10c 18 int ret;
lzzcd001 0:078749d5c10c 19 while (true) {
lzzcd001 0:078749d5c10c 20 ret = sock.receive(buffer, sizeof(buffer)-1);
lzzcd001 0:078749d5c10c 21 if (ret <= 0)
lzzcd001 0:078749d5c10c 22 break;
lzzcd001 0:078749d5c10c 23 buffer[ret] = '\0';
lzzcd001 0:078749d5c10c 24 printf("Received %d chars from server:\n%s\n", ret, buffer);
lzzcd001 0:078749d5c10c 25 }
lzzcd001 0:078749d5c10c 26
lzzcd001 0:078749d5c10c 27 sock.close();
lzzcd001 0:078749d5c10c 28
lzzcd001 0:078749d5c10c 29 eth.disconnect();
lzzcd001 0:078749d5c10c 30
lzzcd001 0:078749d5c10c 31 while(1) {}
lzzcd001 0:078749d5c10c 32 }
lzzcd001 0:078749d5c10c 33