fix the problem http request with '\0' and fixx query string in url

Fork of mbed-http by sandbox

Revision:
7:2e3eedb9ca5c
Parent:
0:910f5949759f
Child:
10:ec9b75c349aa
--- a/source/http_request_builder.h	Thu Feb 23 14:11:47 2017 +0100
+++ b/source/http_request_builder.h	Fri Feb 24 11:20:16 2017 +0100
@@ -80,8 +80,14 @@
         char* req = (char*)calloc(size + 1, 1);
         char* originalReq = req;
 
-        sprintf(req, "%s %s%s HTTP/1.1\r\n", method_str, parsed_url->path(), parsed_url->query());
-        req += strlen(method_str) + 1 + strlen(parsed_url->path()) + strlen(parsed_url->query()) + 1 + 8 + 2;
+        if (strcmp(parsed_url->query(), "") == 0) {
+            sprintf(req, "%s %s HTTP/1.1\r\n", method_str, parsed_url->path());
+            req += strlen(method_str) + 1 + strlen(parsed_url->path()) + 1 + 8 + 2;
+        }
+        else {
+            sprintf(req, "%s %s?%s HTTP/1.1\r\n", method_str, parsed_url->path(), parsed_url->query());
+            req += strlen(method_str) + 1 + strlen(parsed_url->path()) + 1 + strlen(parsed_url->query()) + 1 + 8 + 2;
+        }
 
         typedef map<string, string>::iterator it_type;
         for(it_type it = headers.begin(); it != headers.end(); it++) {