@@ -123,6 +123,8 @@ using namespace lklibs;
123
123
124
124
int main () {
125
125
126
+ HttpClient httpClient;
127
+
126
128
auto future1 = httpClient.getRequest("https://api.myproject.com/foo");
127
129
auto future2 = httpClient.getRequest("https://api.myproject.com/bar");
128
130
auto future3 = httpClient.getRequest("https://api.myproject.com/baz");
@@ -163,6 +165,8 @@ using namespace lklibs;
163
165
164
166
int main () {
165
167
168
+ HttpClient httpClient;
169
+
166
170
auto response = httpClient.getRequest("https://www.myinvalidurl.com").get();
167
171
168
172
// Instead of throwing an exception, the succeed field of the response object is set to false
@@ -195,6 +199,8 @@ using namespace lklibs;
195
199
196
200
int main () {
197
201
202
+ HttpClient httpClient;
203
+
198
204
// If you need to retrieve binary data such as an image, just pass the "returnAsBinary" parameter as true
199
205
auto response = httpClient.getRequest("https://api.myproject.com/image/7", true).get();
200
206
@@ -222,7 +228,9 @@ using namespace lklibs;
222
228
223
229
int main () {
224
230
225
- // You can send custom headers in a string/string map
231
+ HttpClient httpClient;
232
+
233
+ // You can send custom headers in a string/string map
226
234
auto headers = std::map<std::string, std::string>();
227
235
228
236
headers["Custom-Header1"] = "value1";
@@ -250,6 +258,8 @@ using namespace lklibs;
250
258
251
259
int main () {
252
260
261
+ HttpClient httpClient;
262
+
253
263
// You can send a POST request with form data in the payload
254
264
std::string payload = "param1=7¶m2=test";
255
265
@@ -277,6 +287,8 @@ using namespace lklibs;
277
287
278
288
int main () {
279
289
290
+ HttpClient httpClient;
291
+
280
292
std::string payload = R"({"param1": 7, "param2": "test"})";
281
293
282
294
// You need to send the "Content-Type" as "application/json" in the HTTP Header, if you need to send json data in the payload
@@ -307,6 +319,8 @@ using namespace lklibs;
307
319
308
320
int main () {
309
321
322
+ HttpClient httpClient;
323
+
310
324
std::string payload = "param1=7¶m2=test";
311
325
312
326
auto future1 = httpClient.putRequest("https://api.myproject.com", payload);
0 commit comments