A HTTP Client for the mbed networking libraries. Work with Xively. Send location using PUT request.

Fork of HTTPClient by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
olympux
Date:
Mon Apr 28 20:15:40 2014 +0000
Parent:
16:1f743885e7de
Commit message:
Send X-ApiKey header

Changed in this revision

HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPClient.cpp	Thu Aug 30 15:38:57 2012 +0000
+++ b/HTTPClient.cpp	Mon Apr 28 20:15:40 2014 +0000
@@ -18,7 +18,7 @@
  */
 
 //Debug is disabled by default
-#if 0
+#if 1
 //Enable debug
 #include <cstdio>
 #define DBG(x, ...) std::printf("[HTTPClient : DBG]"x"\r\n", ##__VA_ARGS__); 
@@ -126,8 +126,8 @@
 
   char scheme[8];
   uint16_t port;
-  char host[32];
-  char path[64];
+  char host[32]; // default is 32
+  char path[64]; // default is 64
   //First we need to parse the url (http[s]://host[:port][/[path]]) -- HTTPS not supported (yet?)
   HTTPResult res = parseURL(url, scheme, sizeof(scheme), host, sizeof(host), &port, path, sizeof(path));
   if(res != HTTP_OK)
@@ -173,6 +173,7 @@
 
   //Send default headers
   DBG("Sending headers");
+  send("X-ApiKey: DcO8pnBiF4N0xyT9cPeQLggUHuNu7g8dwYhxH6s1qjZwtZm5\r\n");
   if( pDataOut != NULL )
   {
     if( pDataOut->getIsChunked() )
@@ -196,9 +197,9 @@
   }
   
   //Close headers
-  DBG("Headers sent");
   ret = send("\r\n");
   CHECK_CONN_ERR(ret);
+  DBG("Headers sent");
 
   size_t trfLen;
   
@@ -247,7 +248,6 @@
         break;
       }
     }
-
   }
   
   //Receive response
@@ -278,6 +278,7 @@
   {
     //Did not return a 2xx code; TODO fetch headers/(&data?) anyway and implement a mean of writing/reading headers 
     WARN("Response code %d", m_httpResponseCode);
+    DBG("Response: %s%",buf);
     PRTCL_ERR();
   }
 
@@ -546,6 +547,7 @@
     len = strlen(buf);
   }
   DBG("Trying to write %d bytes", len);
+  DBG("%s", buf);
   size_t writtenLen = 0;
     
   if(!m_sock.is_connected())
@@ -585,6 +587,7 @@
     return HTTP_PARSE; //URL is invalid
   }
 
+  DBG("%s",host);
   if( maxSchemeLen < hostPtr - schemePtr + 1 ) //including NULL-terminating char
   {
     WARN("Scheme str is too small (%d >= %d)", maxSchemeLen, hostPtr - schemePtr + 1);