Beispiel HTTP GET

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of HTTP_GET by th.iotkit2.ch

Committer:
stefan1691
Date:
Mon Jun 08 12:21:03 2015 +0000
Revision:
6:5fbd3b258558
Parent:
5:6ceed3b62b0e
Child:
9:d95493db94c6
Richtiger REST Aufruf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stefan1691 3:aad64a4b6ff6 1 /** Beispiel HTTP GET
marcel1691 1:2e29a33cd918 2 */
WiredHome 0:fb5060c39dd1 3 #include "mbed.h"
WiredHome 0:fb5060c39dd1 4 #include "HTTPClient.h"
marcel1691 1:2e29a33cd918 5 #include "HTTPText.h"
WiredHome 0:fb5060c39dd1 6 #include "EthernetInterface.h"
WiredHome 0:fb5060c39dd1 7
WiredHome 0:fb5060c39dd1 8 EthernetInterface eth;
stefan1691 3:aad64a4b6ff6 9 // HTTPClient Hilfsklasse
WiredHome 0:fb5060c39dd1 10 HTTPClient http;
stefan1691 3:aad64a4b6ff6 11 // I/O Buffer
marcel1691 1:2e29a33cd918 12 char message[6000];
WiredHome 0:fb5060c39dd1 13
WiredHome 0:fb5060c39dd1 14 DigitalOut myled(LED1);
WiredHome 0:fb5060c39dd1 15
marcel1691 1:2e29a33cd918 16 int main()
marcel1691 1:2e29a33cd918 17 {
stefan1691 3:aad64a4b6ff6 18 printf("HTTP Client - GET\n");
WiredHome 0:fb5060c39dd1 19 eth.init();
WiredHome 0:fb5060c39dd1 20 eth.connect();
WiredHome 0:fb5060c39dd1 21
marcel1691 1:2e29a33cd918 22 while(1)
marcel1691 1:2e29a33cd918 23 {
WiredHome 0:fb5060c39dd1 24 myled = 1;
stefan1691 5:6ceed3b62b0e 25
marcel1691 1:2e29a33cd918 26 int ret = http.get("http://developer.mbed.org/media/uploads/mbed_official/hello.txt", message, sizeof(message));
stefan1691 5:6ceed3b62b0e 27 // lokale Variante mit CGI-Script auf Raspberry Pi. Wenn nicht Funktioniert: raspi2x durch IP-Adresse ersetzen
stefan1691 6:5fbd3b258558 28 //int ret = http.get("http://raspi2x/cgi-bin/rest/timestamp", message, sizeof(message));
marcel1691 1:2e29a33cd918 29 if ( !ret )
marcel1691 1:2e29a33cd918 30 {
WiredHome 0:fb5060c39dd1 31 printf("Success - read %d characters.\r\n", strlen(message));
WiredHome 0:fb5060c39dd1 32 printf("%s\r\n", message);
WiredHome 0:fb5060c39dd1 33 }
marcel1691 1:2e29a33cd918 34 else
marcel1691 1:2e29a33cd918 35 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
marcel1691 1:2e29a33cd918 36
WiredHome 0:fb5060c39dd1 37 myled = 0;
marcel1691 1:2e29a33cd918 38
WiredHome 0:fb5060c39dd1 39 wait(10);
WiredHome 0:fb5060c39dd1 40 }
stefan1691 3:aad64a4b6ff6 41 eth.disconnect();
WiredHome 0:fb5060c39dd1 42 }