-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHttpClient.h
More file actions
50 lines (39 loc) · 1.16 KB
/
HttpClient.h
File metadata and controls
50 lines (39 loc) · 1.16 KB
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
// HttpClient.h
#ifndef HTTP_CLIENT_H_
#define HTTP_CLIENT_H_
/***************************************************************
HttpClient based libcurl
***************************************************************/
#include <curl/curl.h>
#pragma comment (lib, "Crypt32.lib")
#pragma comment (lib, "ws2_32.lib")
#pragma comment (lib, "winmm.lib")
#pragma comment (lib, "wldap32.lib")
#include "HttpRequest.h"
class HttpClient {
public:
HttpClient();
~HttpClient();
int Send(const HttpRequest& req, HttpResponse* res);
static const char* strerror(int errcode);
void SetTimeout(int sec) { m_timeout = sec; }
void AddHeader(string key, string value) {
m_headers[key] = value;
}
void DelHeader(string key) {
auto iter = m_headers.find(key);
if (iter != m_headers.end()) {
m_headers.erase(iter);
}
}
void ClearHeader() {
m_headers.clear();
}
CURLcode dl_curl_get_req(const std::string& url, std::string filename);
protected:
int curl(const HttpRequest& req, HttpResponse* res);
private:
int m_timeout; // unit:s default:10s
KeyValue m_headers;
};
#endif // HTTP_CLIENT_H_