Allocate content buffer dynamically.
This commit is contained in:
parent
874ceb93b6
commit
c4b83f1bff
2 changed files with 9 additions and 9 deletions
|
@ -1,13 +1,16 @@
|
|||
#include "http_client.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
std::unique_ptr<char[]> myBodyBuffer = nullptr;
|
||||
uint16_t offset{0};
|
||||
bool received{false};
|
||||
|
||||
void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res,
|
||||
err_t err) {
|
||||
#ifdef DEBUG
|
||||
printf("Transfer complete\n");
|
||||
// printf("Local result=%d\n", httpc_result);
|
||||
// printf("Http result=%d\n", srv_res);
|
||||
#endif
|
||||
received = true;
|
||||
offset = 0;
|
||||
|
@ -17,9 +20,10 @@ err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, u
|
|||
u32_t content_len) {
|
||||
#ifdef DEBUG
|
||||
printf("Headers received\n");
|
||||
printf("Content length=%d\n", content_len);
|
||||
printf("Header length=%d\n", hdr_len);
|
||||
printf("Content length=%lu\n", content_len);
|
||||
printf("Header length=%u\n", hdr_len);
|
||||
#endif
|
||||
myBodyBuffer = std::make_unique<char[]>(content_len + 1);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
@ -64,7 +68,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() {
|
|||
sleep_ms(1000);
|
||||
}
|
||||
|
||||
result.append(myBodyBuffer);
|
||||
result.append(myBodyBuffer.get());
|
||||
received = false;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include "pico/cyw43_arch.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
static char myBodyBuffer[2048];
|
||||
static uint16_t offset{0};
|
||||
static bool received{false};
|
||||
|
||||
void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res,
|
||||
err_t err);
|
||||
|
||||
|
|
Loading…
Reference in a new issue