Related to !248: completed synchronous request() fixes
This commit is contained in:
parent
49e2bb9261
commit
c6c7d0a6f2
5 changed files with 160 additions and 124 deletions
|
|
@ -215,31 +215,35 @@ int main() {
|
|||
cout << "Server listening on port " << server_port.get_future().get() << endl << endl;
|
||||
|
||||
// Client examples
|
||||
HttpsClient client("localhost:8080", false); // Second create() parameter set to false: no certificate verification
|
||||
|
||||
string json_string = "{\"firstName\": \"John\",\"lastName\": \"Smith\",\"age\": 25}";
|
||||
|
||||
// Synchronous request examples
|
||||
try {
|
||||
cout << "Example GET request to https://localhost:8080/match/123" << endl;
|
||||
auto r1 = client.request("GET", "/match/123");
|
||||
cout << "Response content: " << r1->content.rdbuf() << endl << endl; // Alternatively, use the convenience function r1->content.string()
|
||||
{
|
||||
HttpsClient client("localhost:8080", false);
|
||||
try {
|
||||
cout << "Example GET request to http://localhost:8080/match/123" << endl;
|
||||
auto r1 = client.request("GET", "/match/123");
|
||||
cout << "Response content: " << r1->content.rdbuf() << endl << endl; // Alternatively, use the convenience function r1->content.string()
|
||||
|
||||
cout << "Example POST request to https://localhost:8080/string" << endl;
|
||||
auto r2 = client.request("POST", "/string", json_string);
|
||||
cout << "Response content: " << r2->content.rdbuf() << endl << endl;
|
||||
}
|
||||
catch(const SimpleWeb::system_error &e) {
|
||||
cerr << "Client request error: " << e.what() << endl;
|
||||
cout << "Example POST request to http://localhost:8080/string" << endl;
|
||||
auto r2 = client.request("POST", "/string", json_string);
|
||||
cout << "Response content: " << r2->content.rdbuf() << endl << endl;
|
||||
}
|
||||
catch(const SimpleWeb::system_error &e) {
|
||||
cerr << "Client request error: " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Asynchronous request example
|
||||
cout << "Example POST request to https://localhost:8080/json" << endl;
|
||||
client.request("POST", "/json", json_string, [](shared_ptr<HttpsClient::Response> response, const SimpleWeb::error_code &ec) {
|
||||
if(!ec)
|
||||
cout << "Response content: " << response->content.rdbuf() << endl;
|
||||
});
|
||||
client.io_service->run();
|
||||
{
|
||||
HttpsClient client("localhost:8080", false);
|
||||
cout << "Example POST request to http://localhost:8080/json" << endl;
|
||||
client.request("POST", "/json", json_string, [](shared_ptr<HttpsClient::Response> response, const SimpleWeb::error_code &ec) {
|
||||
if(!ec)
|
||||
cout << "Response content: " << response->content.rdbuf() << endl;
|
||||
});
|
||||
client.io_service->run();
|
||||
}
|
||||
|
||||
server_thread.join();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue