blob: a587c674de672a7316fa761e9dedb467ce53a470 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/* Copyright (C) 2022 The Qt Company Ltd.
*
* SPDX-License-Identifier: GPL-3.0-only WITH Qt-GPL-exception-1.0
*/
#pragma once
#include <iostream>
#include <sstream>
#include <map>
#define SERVER_CONN_TIMEOUT 10
#if _WIN32
#include "curl/curl.h"
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include <curl/curl.h>
#endif
struct HttpRequest {
std::string payload;
std::string url;
std::string reply;
curl_slist *headers = nullptr;
};
/*********************
HttpClient class
*/
class HttpClient
{
public:
explicit HttpClient(const std::string &serverUrl,
const std::string &requestAccessPoint,
const std::string &permanentccessPoint,
const std::string &versionAccessPoint);
~HttpClient() {}
int sendRequest(std::string &reply, const std::string &payload,
const std::string &server, const std::string &authKey="");
std::string error() { return m_lastError; }
private:
std::string m_serverUrl;
std::string m_requestAccessPoint;
std::string m_permanentAccessPoint;
std::string m_versionAccessPoint;
std::string m_userAgent = "License daemon / ";
std::string m_lastError;
int doRequest(CURL *curl, HttpRequest &request);
};
|