/
sxfour
/
cpp_winapi_all_projects
Обзор
Документация
Войти
/
sxfour
/
cpp_winapi_all_projects
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
WinAPI_RestAPI_Upload/rest_winapi.h
68 строк
2 KB
Egor Levashov
Add files via upload
26 апр 2024, 19:08
Не верифицирован
26 апр 2024, 19:08
cf31e97
Код
Авторство
О чём код?
#pragma once #include <string> #include <cpr/cpr.h> #include <nlohmann/json.hpp> namespace urls { constexpr std::string_view get_jwt_url{ "http://127.0.0.1:7631/teploset_api/token/" }; constexpr std::string_view upload_arh_url{ "http://127.0.0.1:7631/teploset_docs/" }; constexpr std::string_view test_conn{ "http://127.0.0.1:7631/" }; constexpr std::string_view auth_jwt_body{ "{\"username\": \"root\", \"password\":\"toor\"}" }; } // ��������� ������ ������ std::string get_jwt_refresh() { cpr::Response jwt_resp_r = cpr::Post( cpr::Url{ urls::get_jwt_url }, cpr::Body{ urls::auth_jwt_body }, cpr::Header{ {"Content-Type", "application/json"} }, cpr::Timeout{ 1000 } ); if (jwt_resp_r.status_code == 200) { const std::string jwt_resp_data = jwt_resp_r.text; return jwt_resp_data; } return jwt_resp_r.error.message; } // �������� ���������� �� ������� int test_conn() { cpr::Response test_conn_resp = cpr::Get( cpr::Url{ urls::test_conn }, cpr::Timeout{ 1000 } ); if (test_conn_resp.status_code == 404) { return 1; } else { return 0; } } // ������ ������ � json int write_to_json(const std::string json_data, std::string file_name) { std::fstream file; file.open(file_name, std::ios_base::out); if (!file.is_open()) { return 0; } file.write(json_data.data(), json_data.size()); file.close(); return 1; } // ���������� � json nlohmann::json read_data_json(std::string file_name) { std::ifstream f(file_name); nlohmann::json data = nlohmann::json::parse(f); return data; }