A HTTP/HTTPS Client for the mbed networking/CyaSSL ssl library

Dependents:   Anpi dropbox_access php_access_auth TwitterReader ... more

Fork of HTTPClient by Donatien Garnier

HTTP and HTTPS Client Class with wolfSSL, embedded SSL library.

/media/uploads/wolfSSL/wolfssl_logo.png

The class was forked from http://mbed.org/users/donatien/code/HTTPClient/

It, now, accepts url both with "http://" and "https://".

Allocate caller thread with 16kbytes or larger stack for "https" requests.

Rest of the API stays compatible with HTTPClient.

For more about the library, see http://www.wolfssl.com. http://wolfssl.com/yaSSL/Docs.html.

Extended methods:

  • HTTPResult basicAuth(const char* user, const char* password); /* set id/passwd for basic Authentication */
  • void setHeader(char *header) ; /* set http headers */
  • HTTPResult setSSLversion(int minorV) ; /* set SSL/TLS version. 0: SSL3, 1: TLS1.0, 2: TLS1.1, 3: TLS1.2 */
Revision:
9:ff30cc189191
Parent:
8:45c8da29a1cf
Child:
10:e1351de84c16
--- a/HTTPClient.cpp	Fri Jul 06 10:26:17 2012 +0000
+++ b/HTTPClient.cpp	Wed Jul 11 21:25:29 2012 +0000
@@ -137,10 +137,10 @@
 
   //Send request
   DBG("Sending request");
-  char line[128];
+  char buf[CHUNK_SIZE];
   const char* meth = (method==HTTP_GET)?"GET":(method==HTTP_POST)?"POST":"";
-  snprintf(line, sizeof(line), "%s %s HTTP/1.1\r\nHost: %s\r\n", meth, path, host); //Write request
-  ret = send(line);
+  snprintf(buf, sizeof(buf), "%s %s HTTP/1.1\r\nHost: %s\r\n", meth, path, host); //Write request
+  ret = send(buf);
   if(ret)
   {
     m_sock.close();
@@ -161,27 +161,26 @@
     }
     else
     {
-      snprintf(line, sizeof(line), "Content-Length: %d\r\n", pDataOut->getDataLen());
-      ret = send(line);
+      snprintf(buf, sizeof(buf), "Content-Length: %d\r\n", pDataOut->getDataLen());
+      ret = send(buf);
       CHECK_CONN_ERR(ret);
     }
     char type[48];
     if( pDataOut->getDataType(type, 48) == OK )
     {
-      snprintf(line, sizeof(line), "Content-Type: %s\r\n", type);
-      ret = send(line);
+      snprintf(buf, sizeof(buf), "Content-Type: %s\r\n", type);
+      ret = send(buf);
       CHECK_CONN_ERR(ret);
     }
   }
-
+  
   //Close headers
   DBG("Headers sent");
   ret = send("\r\n");
   CHECK_CONN_ERR(ret);
 
-  char buf[CHUNK_SIZE];
   size_t trfLen;
-
+  
   //Send data (if POST)
   if( (method == HTTP_POST) && (pDataOut != NULL) )
   {
@@ -193,8 +192,9 @@
       if( pDataOut->getIsChunked() )
       {
         //Write chunk header
-        snprintf(line, sizeof(line), "%X\r\n", trfLen); //In hex encoding
-        ret = send(line);
+        char chunkHeader[16];
+        snprintf(chunkHeader, sizeof(chunkHeader), "%X\r\n", trfLen); //In hex encoding
+        ret = send(chunkHeader);
         CHECK_CONN_ERR(ret);
       }
       else if( trfLen == 0 )
@@ -228,7 +228,7 @@
     }
 
   }
-
+  
   //Receive response
   DBG("Receiving response");
   ret = recv(buf, CHUNK_SIZE - 1, CHUNK_SIZE - 1, &trfLen); //Read n bytes