[HTTP] Fixed incorrect string length
This commit is contained in:
parent
14df1d8c52
commit
4eef30a2a4
1 changed files with 9 additions and 9 deletions
|
@ -21,7 +21,7 @@ int16_t HTTPClient::get(const char* url, String& response) {
|
||||||
char* hostEnd = strchr(hostStart + 1, '/');
|
char* hostEnd = strchr(hostStart + 1, '/');
|
||||||
host = new char[hostEnd - hostStart];
|
host = new char[hostEnd - hostStart];
|
||||||
strncpy(host, hostStart + 1, hostEnd - hostStart - 1);
|
strncpy(host, hostStart + 1, hostEnd - hostStart - 1);
|
||||||
host[hostEnd - hostStart - 1] = 0x00;
|
host[hostEnd - hostStart - 1] = '\0';
|
||||||
|
|
||||||
// find the endpoint string
|
// find the endpoint string
|
||||||
endpoint = new char[url + strlen(url) - hostEnd + 1];
|
endpoint = new char[url + strlen(url) - hostEnd + 1];
|
||||||
|
@ -31,7 +31,7 @@ int16_t HTTPClient::get(const char* url, String& response) {
|
||||||
char* hostEnd = strchr(url, '/');
|
char* hostEnd = strchr(url, '/');
|
||||||
host = new char[hostEnd - url + 1];
|
host = new char[hostEnd - url + 1];
|
||||||
strncpy(host, url, hostEnd - url);
|
strncpy(host, url, hostEnd - url);
|
||||||
host[hostEnd - url] = 0x00;
|
host[hostEnd - url] = '\0';
|
||||||
|
|
||||||
// find the endpoint string
|
// find the endpoint string
|
||||||
endpoint = new char[url + strlen(url) - hostEnd + 1];
|
endpoint = new char[url + strlen(url) - hostEnd + 1];
|
||||||
|
@ -39,7 +39,7 @@ int16_t HTTPClient::get(const char* url, String& response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// build the GET request
|
// build the GET request
|
||||||
char* request = new char[strlen(endpoint) + strlen(host) + 25];
|
char* request = new char[strlen(endpoint) + strlen(host) + 25 + 1];
|
||||||
strcpy(request, "GET ");
|
strcpy(request, "GET ");
|
||||||
strcat(request, endpoint);
|
strcat(request, endpoint);
|
||||||
strcat(request, " HTTP/1.1\r\nHost: ");
|
strcat(request, " HTTP/1.1\r\nHost: ");
|
||||||
|
@ -72,7 +72,7 @@ int16_t HTTPClient::get(const char* url, String& response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the response
|
// read the response
|
||||||
char* raw = new char[numBytes];
|
char* raw = new char[numBytes + 1];
|
||||||
size_t rawLength = _tl->receive((uint8_t*)raw, numBytes);
|
size_t rawLength = _tl->receive((uint8_t*)raw, numBytes);
|
||||||
if(rawLength == 0) {
|
if(rawLength == 0) {
|
||||||
delete[] raw;
|
delete[] raw;
|
||||||
|
@ -92,9 +92,9 @@ int16_t HTTPClient::get(const char* url, String& response) {
|
||||||
delete[] raw;
|
delete[] raw;
|
||||||
return(ERR_RESPONSE_MALFORMED);
|
return(ERR_RESPONSE_MALFORMED);
|
||||||
}
|
}
|
||||||
char* responseStr = new char[raw + rawLength - responseStart - 1];
|
char* responseStr = new char[raw + rawLength - responseStart - 1 + 1];
|
||||||
strncpy(responseStr, responseStart + 2, raw + rawLength - responseStart - 1);
|
strncpy(responseStr, responseStart + 2, raw + rawLength - responseStart - 1);
|
||||||
responseStr[raw + rawLength - responseStart - 2] = 0x00;
|
responseStr[raw + rawLength - responseStart - 2] = '\0';
|
||||||
response = String(responseStr);
|
response = String(responseStr);
|
||||||
delete[] responseStr;
|
delete[] responseStr;
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ int16_t HTTPClient::post(const char* url, const char* content, String& response,
|
||||||
char* hostEnd = strchr(hostStart + 1, '/');
|
char* hostEnd = strchr(hostStart + 1, '/');
|
||||||
host = new char[hostEnd - hostStart];
|
host = new char[hostEnd - hostStart];
|
||||||
strncpy(host, hostStart + 1, hostEnd - hostStart - 1);
|
strncpy(host, hostStart + 1, hostEnd - hostStart - 1);
|
||||||
host[hostEnd - hostStart - 1] = 0x00;
|
host[hostEnd - hostStart - 1] = '\0';
|
||||||
|
|
||||||
// find the endpoint string
|
// find the endpoint string
|
||||||
endpoint = new char[url + strlen(url) - hostEnd + 1];
|
endpoint = new char[url + strlen(url) - hostEnd + 1];
|
||||||
|
@ -132,7 +132,7 @@ int16_t HTTPClient::post(const char* url, const char* content, String& response,
|
||||||
char* hostEnd = strchr(url, '/');
|
char* hostEnd = strchr(url, '/');
|
||||||
host = new char[hostEnd - url + 1];
|
host = new char[hostEnd - url + 1];
|
||||||
strncpy(host, url, hostEnd - url);
|
strncpy(host, url, hostEnd - url);
|
||||||
host[hostEnd - url] = 0x00;
|
host[hostEnd - url] = '\0';
|
||||||
|
|
||||||
// find the endpoint string
|
// find the endpoint string
|
||||||
endpoint = new char[url + strlen(url) - hostEnd + 1];
|
endpoint = new char[url + strlen(url) - hostEnd + 1];
|
||||||
|
@ -142,7 +142,7 @@ int16_t HTTPClient::post(const char* url, const char* content, String& response,
|
||||||
// build the POST request
|
// build the POST request
|
||||||
char contentLengthStr[8];
|
char contentLengthStr[8];
|
||||||
itoa(strlen(content), contentLengthStr, 10);
|
itoa(strlen(content), contentLengthStr, 10);
|
||||||
char* request = new char[strlen(endpoint) + strlen(host) + strlen(contentType) + strlen(contentLengthStr) + strlen(content) + 64];
|
char* request = new char[strlen(endpoint) + strlen(host) + strlen(contentType) + strlen(contentLengthStr) + strlen(content) + 64 + 1];
|
||||||
strcpy(request, "POST ");
|
strcpy(request, "POST ");
|
||||||
strcat(request, endpoint);
|
strcat(request, endpoint);
|
||||||
strcat(request, " HTTP/1.1\r\nHost: ");
|
strcat(request, " HTTP/1.1\r\nHost: ");
|
||||||
|
|
Loading…
Add table
Reference in a new issue