@@ -70,10 +70,10 @@ using namespace lklibs;
70
70
71
71
int main () {
72
72
73
- HttpClient httpClient ;
73
+ HttpRequest httpRequest ;
74
74
75
75
// The simplest but slowest method if multiple calls will be made
76
- auto response = httpClient .getRequest("https://api.myproject.com?param1=7¶m2=test").get();
76
+ auto response = httpRequest .getRequest("https://api.myproject.com?param1=7¶m2=test").get();
77
77
78
78
std::cout << "Succeed: " << response.succeed << std::endl;
79
79
std::cout << "Http Status Code: " << response.statusCode << std::endl;
@@ -98,13 +98,13 @@ using namespace lklibs;
98
98
99
99
int main () {
100
100
101
- HttpClient httpClient ;
101
+ HttpRequest httpRequest ;
102
102
103
- auto response1 = httpClient .getRequest("https://api.myproject.com/foo").get();
104
- auto response2 = httpClient .getRequest("https://api.myproject.com/bar").get();
105
- auto response3 = httpClient .getRequest("https://api.myproject.com/baz").get();
106
- auto response4 = httpClient .getRequest("https://api.myproject.com/qux").get();
107
- auto response5 = httpClient .getRequest("https://api.myproject.com/quux").get();
103
+ auto response1 = httpRequest .getRequest("https://api.myproject.com/foo").get();
104
+ auto response2 = httpRequest .getRequest("https://api.myproject.com/bar").get();
105
+ auto response3 = httpRequest .getRequest("https://api.myproject.com/baz").get();
106
+ auto response4 = httpRequest .getRequest("https://api.myproject.com/qux").get();
107
+ auto response5 = httpRequest .getRequest("https://api.myproject.com/quux").get();
108
108
109
109
// Takes 2.5 seconds in total
110
110
@@ -124,13 +124,13 @@ using namespace lklibs;
124
124
125
125
int main () {
126
126
127
- HttpClient httpClient ;
127
+ HttpRequest httpRequest ;
128
128
129
- auto future1 = httpClient .getRequest("https://api.myproject.com/foo");
130
- auto future2 = httpClient .getRequest("https://api.myproject.com/bar");
131
- auto future3 = httpClient .getRequest("https://api.myproject.com/baz");
132
- auto future4 = httpClient .getRequest("https://api.myproject.com/qux");
133
- auto future5 = httpClient .getRequest("https://api.myproject.com/quux");
129
+ auto future1 = httpRequest .getRequest("https://api.myproject.com/foo");
130
+ auto future2 = httpRequest .getRequest("https://api.myproject.com/bar");
131
+ auto future3 = httpRequest .getRequest("https://api.myproject.com/baz");
132
+ auto future4 = httpRequest .getRequest("https://api.myproject.com/qux");
133
+ auto future5 = httpRequest .getRequest("https://api.myproject.com/quux");
134
134
135
135
auto response1 = future1.get();
136
136
auto response2 = future2.get();
@@ -166,9 +166,9 @@ using namespace lklibs;
166
166
167
167
int main () {
168
168
169
- HttpClient httpClient ;
169
+ HttpRequest httpRequest ;
170
170
171
- auto response = httpClient .getRequest("https://www.myinvalidurl.com").get();
171
+ auto response = httpRequest .getRequest("https://www.myinvalidurl.com").get();
172
172
173
173
// Instead of throwing an exception, the succeed field of the response object is set to false
174
174
std::cout << "Succeed: " << response.succeed << std::endl;
@@ -200,10 +200,10 @@ using namespace lklibs;
200
200
201
201
int main () {
202
202
203
- HttpClient httpClient ;
203
+ HttpRequest httpRequest ;
204
204
205
205
// If you need to retrieve binary data such as an image, just pass the "returnAsBinary" parameter as true
206
- auto response = httpClient .getRequest("https://api.myproject.com/image/7", true).get();
206
+ auto response = httpRequest .getRequest("https://api.myproject.com/image/7", true).get();
207
207
208
208
std::cout << "Succeed: " << response.succeed << std::endl;
209
209
std::cout << "Http Status Code: " << response.statusCode << std::endl;
@@ -229,15 +229,15 @@ using namespace lklibs;
229
229
230
230
int main () {
231
231
232
- HttpClient httpClient ;
232
+ HttpRequest httpRequest ;
233
233
234
234
// You can send custom headers in a string/string map
235
235
auto headers = std::map<std::string, std::string>();
236
236
237
237
headers["Custom-Header1"] = "value1";
238
238
headers["Custom-Header2"] = "value2";
239
239
240
- auto response = httpClient .getRequest("https://api.myproject.com?param1=7¶m2=test", headers).get();
240
+ auto response = httpRequest .getRequest("https://api.myproject.com?param1=7¶m2=test", headers).get();
241
241
242
242
std::cout << "Succeed: " << response.succeed << std::endl;
243
243
@@ -259,12 +259,12 @@ using namespace lklibs;
259
259
260
260
int main () {
261
261
262
- HttpClient httpClient ;
262
+ HttpRequest httpRequest ;
263
263
264
264
// You can send a POST request with form data in the payload
265
265
std::string payload = "param1=7¶m2=test";
266
266
267
- auto response = httpClient .postRequest("https://api.myproject.com", payload).get();
267
+ auto response = httpRequest .postRequest("https://api.myproject.com", payload).get();
268
268
269
269
std::cout << "Succeed: " << response.succeed << std::endl;
270
270
std::cout << "Http Status Code: " << response.statusCode << std::endl;
@@ -288,7 +288,7 @@ using namespace lklibs;
288
288
289
289
int main () {
290
290
291
- HttpClient httpClient ;
291
+ HttpRequest httpRequest ;
292
292
293
293
std::string payload = R"({"param1": 7, "param2": "test"})";
294
294
@@ -297,7 +297,7 @@ int main() {
297
297
298
298
headers["Content-Type"] = "application/json";
299
299
300
- auto response = httpClient .postRequest("https://api.myproject.com", payload, headers).get();
300
+ auto response = httpRequest .postRequest("https://api.myproject.com", payload, headers).get();
301
301
302
302
std::cout << "Succeed: " << response.succeed << std::endl;
303
303
std::cout << "Http Status Code: " << response.statusCode << std::endl;
@@ -320,13 +320,13 @@ using namespace lklibs;
320
320
321
321
int main () {
322
322
323
- HttpClient httpClient ;
323
+ HttpRequest httpRequest ;
324
324
325
325
std::string payload = "param1=7¶m2=test";
326
326
327
- auto future1 = httpClient .putRequest("https://api.myproject.com", payload);
328
- auto future2 = httpClient .deleteRequest("https://api.myproject.com", payload);
329
- auto future3 = httpClient .patchRequest("https://api.myproject.com?param1=7¶m2=test");
327
+ auto future1 = httpRequest .putRequest("https://api.myproject.com", payload);
328
+ auto future2 = httpRequest .deleteRequest("https://api.myproject.com", payload);
329
+ auto future3 = httpRequest .patchRequest("https://api.myproject.com?param1=7¶m2=test");
330
330
331
331
auto response1 = future1.get();
332
332
auto response2 = future2.get();
@@ -341,7 +341,7 @@ int main() {
341
341
342
342
If you need to ignore SSL certificate errors for any valid reason, you can continue
343
343
working by passing ** "true"** value to the ** "ignoreSslErrors"** variable of the
344
- HttpClient class.
344
+ HttpRequest class.
345
345
346
346
``` cpp
347
347
#include < fstream>
@@ -351,12 +351,12 @@ using namespace lklibs;
351
351
352
352
int main () {
353
353
354
- HttpClient httpClient ;
354
+ HttpRequest httpRequest ;
355
355
356
356
// If you need to ignore SSL errors, you can set the "ignoreSslErrors" field to true
357
- httpClient .ignoreSslErrors = true;
357
+ httpRequest .ignoreSslErrors = true;
358
358
359
- auto response = httpClient .getRequest("https://api.myinvalidssl.com").get();
359
+ auto response = httpRequest .getRequest("https://api.myinvalidssl.com").get();
360
360
361
361
return 0;
362
362
}
0 commit comments