HTTPS client example for GR-peach

Dependencies:   HTTPClient mbed-rtos-initial-thread-larger-stack mbed wolfSSL

Committer:
takashikojo
Date:
Sun Apr 24 06:42:16 2016 +0000
Revision:
5:6d00f26f7b59
Parent:
4:6b0e7a10a395
with wolfSSL3.6.0;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takashikojo 0:83075160de0e 1 #include "mbed.h"
takashikojo 0:83075160de0e 2 #include "EthernetInterface.h"
takashikojo 0:83075160de0e 3 #include "HTTPClient.h"
takashikojo 0:83075160de0e 4
takashikojo 5:6d00f26f7b59 5 #define SERVER_URL "https://192.168.10.15/index.html"
takashikojo 0:83075160de0e 6
takashikojo 0:83075160de0e 7 EthernetInterface eth;
takashikojo 0:83075160de0e 8 HTTPClient http;
takashikojo 0:83075160de0e 9 char recvBuff[1024*20];
takashikojo 0:83075160de0e 10
takashikojo 0:83075160de0e 11 int main()
takashikojo 0:83075160de0e 12 {
takashikojo 4:6b0e7a10a395 13 int ret ;
takashikojo 5:6d00f26f7b59 14 int i ;
takashikojo 5:6d00f26f7b59 15 #define URL_SIZE 100
takashikojo 5:6d00f26f7b59 16 char server_url[URL_SIZE] ;
takashikojo 0:83075160de0e 17
takashikojo 4:6b0e7a10a395 18 printf("HTTP Client, Starting,...\n") ;
takashikojo 0:83075160de0e 19
takashikojo 0:83075160de0e 20 eth.init(); //Use DHCP
takashikojo 0:83075160de0e 21 while(1) {
takashikojo 5:6d00f26f7b59 22 printf("Trying to connect to Ethernet\n") ;
takashikojo 5:6d00f26f7b59 23 if(eth.connect() == 0)break ;
takashikojo 0:83075160de0e 24 }
takashikojo 0:83075160de0e 25 printf("HTTP Client, IP Address is %s\n", eth.getIPAddress());
takashikojo 0:83075160de0e 26
takashikojo 4:6b0e7a10a395 27 while(1) {
takashikojo 5:6d00f26f7b59 28 printf("URL(\"http://.../...\" or \"https://.../...\"):") ;
takashikojo 5:6d00f26f7b59 29 for(i=0; i<sizeof(server_url); i++) {
takashikojo 5:6d00f26f7b59 30 if((server_url[i] = getchar()) == '\r') {
takashikojo 5:6d00f26f7b59 31 server_url[i] = '\0' ;
takashikojo 5:6d00f26f7b59 32 putchar('\n') ;
takashikojo 5:6d00f26f7b59 33 break ;
takashikojo 5:6d00f26f7b59 34 } else putchar(server_url[i]) ;
takashikojo 5:6d00f26f7b59 35 }
takashikojo 5:6d00f26f7b59 36
takashikojo 5:6d00f26f7b59 37 printf("\nTrying to fetch page... %s\n", server_url);
takashikojo 4:6b0e7a10a395 38 memset(recvBuff, '\0', sizeof(recvBuff)) ;
takashikojo 5:6d00f26f7b59 39 ret = http.get(server_url, recvBuff, sizeof(recvBuff),16);
takashikojo 0:83075160de0e 40
takashikojo 4:6b0e7a10a395 41 if (!ret) {
takashikojo 4:6b0e7a10a395 42 printf("Result: %s\n", recvBuff);
takashikojo 4:6b0e7a10a395 43 } else {
takashikojo 4:6b0e7a10a395 44 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
takashikojo 4:6b0e7a10a395 45 }
takashikojo 0:83075160de0e 46 }
takashikojo 0:83075160de0e 47
takashikojo 0:83075160de0e 48 eth.disconnect();
takashikojo 0:83075160de0e 49
takashikojo 0:83075160de0e 50 while(1) {
takashikojo 0:83075160de0e 51 }
takashikojo 4:6b0e7a10a395 52 }