Update Http Library

This commit is contained in:
2020-06-14 16:39:11 +02:00
parent a8381614e8
commit 86af7f0eb8
3 changed files with 30 additions and 10 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ int main(int argc, char** argv)
try try
{ {
Logging::OpenLog(); Logging::OpenLog();
Logging::SetLogMask(Logging::Severity::Debug); Logging::SetLogMask(Logging::Severity::Info);
bool daemon = false; bool daemon = false;
clipp::group cli { clipp::group cli {
+8 -3
View File
@@ -86,7 +86,8 @@ void Device::UpdateDevicesFromInventory()
{ {
try try
{ {
std::string devices = m_httpClient.GetUrlContents(m_inventoryURL); Http::HttpRequest request(m_inventoryURL);
std::string devices = m_httpClient.Open(request);
nlohmann::json json = nlohmann::json::parse(devices); nlohmann::json json = nlohmann::json::parse(devices);
m_dynamicDevices.clear(); m_dynamicDevices.clear();
@@ -229,7 +230,9 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
try try
{ {
m_httpClient.GetUrlSilent(url.str()); Http::HttpRequest request(url.str());
request.ReturnType(Http::HttpRequest::ReturnType::None);
m_httpClient.Open(request);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
@@ -266,7 +269,9 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
{ {
try try
{ {
m_httpClient.GetUrlSilent(url); Http::HttpRequest request(url);
request.ReturnType(Http::HttpRequest::ReturnType::None);
m_httpClient.Open(request);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
+21 -6
View File
@@ -69,7 +69,12 @@ bool Device::Login()
headers.push_back("Content-Type: application/json"); headers.push_back("Content-Type: application/json");
std::stringstream output; std::stringstream output;
output << m_httpClient.GetUrlPostContents(url.str(), headers, m_cookieFile, json.dump()); Http::HttpRequest request(url.str());
request.Method(Http::HttpRequest::Method::POST);
request.Headers(headers);
request.CookieFile(m_cookieFile);
request.Data(json.dump());
output << m_httpClient.Open(request);
nlohmann::json outputJSON = nlohmann::json::parse(output); nlohmann::json outputJSON = nlohmann::json::parse(output);
@@ -105,7 +110,10 @@ void Device::Logout()
try try
{ {
m_httpClient.GetUrlSilent(url.str(), m_cookieFile); Http::HttpRequest request(url.str());
request.ReturnType(Http::HttpRequest::ReturnType::None);
request.CookieFile(m_cookieFile);
m_httpClient.Open(request);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
@@ -153,7 +161,8 @@ void Device::UpdateDevicesFromInventory()
{ {
try try
{ {
std::string devices = m_httpClient.GetUrlContents(m_inventoryURL); Http::HttpRequest request(m_inventoryURL);
std::string devices = m_httpClient.Open(request);
nlohmann::json json = nlohmann::json::parse(devices); nlohmann::json json = nlohmann::json::parse(devices);
m_devices.clear(); m_devices.clear();
@@ -196,7 +205,9 @@ void Device::UpdatePresentDevices()
try try
{ {
std::stringstream output; std::stringstream output;
output << m_httpClient.GetUrlContents(url.str(), m_cookieFile); Http::HttpRequest request(url.str());
request.CookieFile(m_cookieFile);
output << m_httpClient.Open(request);
nlohmann::json json = nlohmann::json::parse(output); nlohmann::json json = nlohmann::json::parse(output);
@@ -296,7 +307,9 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
try try
{ {
m_httpClient.GetUrlSilent(url.str()); Http::HttpRequest request(url.str());
request.ReturnType(Http::HttpRequest::ReturnType::None);
m_httpClient.Open(request);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
@@ -333,7 +346,9 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
{ {
try try
{ {
m_httpClient.GetUrlSilent(url); Http::HttpRequest request(url);
request.ReturnType(Http::HttpRequest::ReturnType::None);
m_httpClient.Open(request);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {