Newer
Older
Import / applications / HighwayDash / ports / Framework / Client.cpp~
@John Ryland John Ryland on 22 Dec 2020 882 bytes import NUC files
#include "HttpClient.h"
#include <stdio.h>
#include <sstream>


void ClientTest()
{
  HttpRequest  request = { "GET", "http://192.168.0.15:8000/servers" };
  HttpResponse result  = MakeHttpRequestWrapper(request);
  std::map<std::string,std::string>& h = result.headers;
  printf("status: %s\n", result.status.c_str());
  for (std::map<std::string, std::string>::const_iterator i = h.begin(); i != h.end(); ++i)
    printf("header[\"%s\"] = \"%s\"\n", i->first.c_str(), i->second.c_str());
  printf("body: %s\n", result.body.data());
}


// Test case
int main(int argc, char *argv[])
{
  if (argc >= 2)
  {
    std::vector<uint8_t> response;
    std::map<std::string,std::string> args;
    int res = MakeHttpRequest(response, "GET", argv[1], args);
    if (response.data())
      printf("%s\n", response.data());
    return res;
  }
  else
  {
    ClientTest();
  }
  return 0;
}