@@ -234,15 +234,24 @@ bool HTTP::error() {
234
234
235
235
// Get Json Object on web server.
236
236
bool HTTP::request (const char * method, const char * endUrl, const char * data, Json::Object* jOutput, const char * content_type){
237
+ Result result;
238
+ request (method, endUrl, data, jOutput, result, content_type);
239
+ return (result == OK);
240
+ }
241
+
242
+ // Get Json Object on web server.
243
+ void HTTP::request (const char * method, const char * endUrl, const char * data, Json::Object* jOutput, Result& result, const char * content_type){
237
244
238
245
std::string output;
239
- if (!request (method, endUrl, data, output, content_type)){
246
+ request (method, endUrl, data, output, result, content_type);
247
+ if (result != OK) {
240
248
241
249
// Give a second chance.
242
250
disconnect ();
243
251
244
- if (!request (method, endUrl, data, output, content_type))
245
- return false ;
252
+ request (method, endUrl, data, output, result, content_type);
253
+ if (result != OK)
254
+ return ;
246
255
}
247
256
248
257
try {
@@ -252,7 +261,8 @@ bool HTTP::request(const char* method, const char* endUrl, const char* data, Jso
252
261
}
253
262
catch (Exception& e){
254
263
printf (" parser() failed in Getter. Exception caught: %s\n " , e.what ());
255
- return false ;
264
+ result = ERROR;
265
+ return ;
256
266
}
257
267
catch (std::exception& e){
258
268
printf (" parser() failed in Getter. std::exception caught: %s\n " , e.what ());
@@ -263,7 +273,7 @@ bool HTTP::request(const char* method, const char* endUrl, const char* data, Jso
263
273
EXCEPTION (" Unknown exception." );
264
274
}
265
275
266
- return true ;
276
+ result = OK ;
267
277
}
268
278
269
279
// Parse the message and split if necessary.
@@ -405,6 +415,12 @@ bool HTTP::write(const std::string& outgoing) {
405
415
406
416
407
417
bool HTTP::request (const char * method, const char * endUrl, const char * data, std::string& output, const char * content_type){
418
+ Result result;
419
+ request (method, endUrl, data, output, result, content_type);
420
+ return (result == OK);
421
+ }
422
+
423
+ void HTTP::request (const char * method, const char * endUrl, const char * data, std::string& output, Result& result, const char * content_type){
408
424
409
425
// / Example of request.
410
426
// / "POST /test.php HTTP/1.0\r\n"
@@ -427,18 +443,17 @@ bool HTTP::request(const char* method, const char* endUrl, const char* data, std
427
443
assert ( !error () );
428
444
assert (output.empty ());
429
445
430
- if (!sendMessage (method, endUrl, data, content_type))
431
- return false ;
446
+ if (!sendMessage (method, endUrl, data, content_type)) {
447
+ result = ERROR;
448
+ return ;
449
+ }
432
450
433
- Result readResult;
434
- readMessage (output, readResult);
435
- if (readResult != OK) {
451
+ readMessage (output, result);
452
+ if (result != OK) {
436
453
437
454
// Clear ouput in case we didn't get the full response.
438
455
if (!output.empty ())
439
456
output.clear ();
440
-
441
- return false ;
442
457
}
443
458
444
459
if (_keepAlive)
@@ -456,7 +471,7 @@ bool HTTP::request(const char* method, const char* endUrl, const char* data, std
456
471
}
457
472
} */
458
473
459
- return true ;
474
+ result = OK ;
460
475
}
461
476
462
477
// Whole process to read the response from HTTP server.
0 commit comments