mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-14 16:58:30 +00:00
Better error handling on client (#601)
This commit is contained in:
parent
cf084e1db1
commit
dc5f9ba164
5 changed files with 727 additions and 657 deletions
|
@ -23,12 +23,12 @@ int main(void) {
|
|||
httplib::Client cli("localhost", 8080);
|
||||
#endif
|
||||
|
||||
auto res = cli.Get("/hi");
|
||||
if (res) {
|
||||
if (auto res = cli.Get("/hi")) {
|
||||
cout << res->status << endl;
|
||||
cout << res->get_header_value("Content-Type") << endl;
|
||||
cout << res->body << endl;
|
||||
} else {
|
||||
cout << "error code: " << res.error() << std::endl;
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
auto result = cli.get_openssl_verify_result();
|
||||
if (result) {
|
||||
|
|
|
@ -17,12 +17,12 @@ int main(void) {
|
|||
auto scheme_host_port = "http://localhost:8080";
|
||||
#endif
|
||||
|
||||
auto res = httplib::Client(scheme_host_port).Get("/hi");
|
||||
|
||||
if (res) {
|
||||
if (auto res = httplib::Client(scheme_host_port).Get("/hi")) {
|
||||
cout << res->status << endl;
|
||||
cout << res->get_header_value("Content-Type") << endl;
|
||||
cout << res->body << endl;
|
||||
} else {
|
||||
cout << res.error() << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue