A HTTP Client for the mbed networking libraries

Dependents:   HTTPClient_Wifly_HelloWorld HTTPPoster HTTPClient_HelloWorld mpod_nhk_english ... more

Fork of HTTPClientLib by Donatien Garnier

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