Simple usage example HTTPClient with wolfSSL

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed wolfSSL

Fork of SimpleHTTPSClient by wolf SSL

Committer:
wolfSSL
Date:
Thu Apr 28 01:13:00 2016 +0000
Revision:
6:81003a418b9c
Parent:
5:12ff922de096
Update wolfSSL to 3.9.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:dadab10758d2 1 #include "mbed.h"
wolfSSL 0:dadab10758d2 2 #include "EthernetInterface.h"
wolfSSL 0:dadab10758d2 3 #include "HTTPClient.h"
wolfSSL 5:12ff922de096 4 #include "getline.h"
wolfSSL 0:dadab10758d2 5
wolfSSL 0:dadab10758d2 6 EthernetInterface eth;
wolfSSL 0:dadab10758d2 7 HTTPClient http;
wolfSSL 0:dadab10758d2 8 char recvBuff[1024*20];
wolfSSL 0:dadab10758d2 9
wolfSSL 2:071a8275fa40 10 void net_main(void const *av)
wolfSSL 0:dadab10758d2 11 {
wolfSSL 0:dadab10758d2 12 int ret ;
wolfSSL 5:12ff922de096 13 char url[100] ;
wolfSSL 0:dadab10758d2 14
wolfSSL 0:dadab10758d2 15 eth.init(); //Use DHCP
wolfSSL 0:dadab10758d2 16 printf("HTTP Client, Starting,...\n") ;
wolfSSL 0:dadab10758d2 17 while(1) {
wolfSSL 0:dadab10758d2 18 if(eth.connect() == 0)break ;
wolfSSL 0:dadab10758d2 19 printf("Retry\n") ;
wolfSSL 0:dadab10758d2 20 }
wolfSSL 5:12ff922de096 21 http.dumpReqHeader(true) ;
wolfSSL 6:81003a418b9c 22 http.dumpResHeader(false) ;
wolfSSL 0:dadab10758d2 23 while(1) {
wolfSSL 5:12ff922de096 24 getline("URL: ", url, sizeof(url)) ;
wolfSSL 5:12ff922de096 25 if(strlen(url) == 0)return ;
wolfSSL 5:12ff922de096 26 /*** HTTP ***/
wolfSSL 5:12ff922de096 27 printf("\nFetching HTTP\n");
wolfSSL 5:12ff922de096 28 ret = http.get(url, recvBuff, sizeof(recvBuff));
wolfSSL 5:12ff922de096 29 if (!ret) {
wolfSSL 5:12ff922de096 30 printf("Result: %s\n", recvBuff);
wolfSSL 5:12ff922de096 31 } else {
wolfSSL 5:12ff922de096 32 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
wolfSSL 5:12ff922de096 33 }
wolfSSL 0:dadab10758d2 34 }
wolfSSL 2:071a8275fa40 35 }
wolfSSL 2:071a8275fa40 36
wolfSSL 2:071a8275fa40 37 main()
wolfSSL 2:071a8275fa40 38 {
wolfSSL 5:12ff922de096 39 #define STACK_SIZE 24000
wolfSSL 2:071a8275fa40 40 Thread t(net_main, NULL, osPriorityNormal, STACK_SIZE);
wolfSSL 2:071a8275fa40 41 while (true) {
wolfSSL 2:071a8275fa40 42 Thread::wait(1000);
wolfSSL 2:071a8275fa40 43 }
wolfSSL 3:41412e91afb0 44 }