36 lines
1.3 KiB
C++
36 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <string>
|
|
|
|
struct HttpResponse {
|
|
long status_code = 0;
|
|
std::string body;
|
|
std::map<std::string, std::string> headers;
|
|
std::string error;
|
|
|
|
bool ok() const {
|
|
return error.empty();
|
|
}
|
|
};
|
|
|
|
class HttpConnection {
|
|
public:
|
|
static HttpResponse get(const std::string &url,
|
|
const std::map<std::string, std::string> &headers = {},
|
|
long timeout_ms = 0);
|
|
|
|
static HttpResponse post(const std::string &url,
|
|
const std::string &body,
|
|
const std::map<std::string, std::string> &headers = {},
|
|
const std::string &content_type = "application/json",
|
|
long timeout_ms = 0);
|
|
|
|
private:
|
|
static HttpResponse performRequest(const std::string &method,
|
|
const std::string &url,
|
|
const std::string &body,
|
|
const std::map<std::string, std::string> &headers,
|
|
const std::string &content_type,
|
|
long timeout_ms);
|
|
}; |