Rework the body of request and response

This commit is contained in:
Chunting Gu
2019-07-03 17:37:44 +08:00
parent b9f2ba6a41
commit 98aeeae012
39 changed files with 1122 additions and 677 deletions
+7 -22
View File
@@ -3,49 +3,34 @@
#include "webcc/client_session.h"
#include "webcc/logger.h"
static void PrintSeparator() {
static const std::string s_line(80, '-');
std::cout << s_line << std::endl;
}
int main() {
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
webcc::ClientSession session;
try {
PrintSeparator();
// Using request builder:
auto r = session.Request(webcc::RequestBuilder{}.Get().
Url("http://httpbin.org/get").
auto r = session.Request(webcc::RequestBuilder{}.
Get("http://httpbin.org/get").
Query("key1", "value1").
Query("key2", "value2").
Date().
Header("Accept", "application/json")
());
std::cout << r->content() << std::endl;
PrintSeparator();
// Using shortcut:
r = session.Get("http://httpbin.org/get",
{ "key1", "value1", "key2", "value2" },
{ "Accept", "application/json" });
std::cout << r->content() << std::endl;
r = session.Request(webcc::RequestBuilder{}.
Post("http://httpbin.org/post").
Body("{'name'='Adam', 'age'=20}").
Json().Utf8()
());
#if WEBCC_ENABLE_SSL
PrintSeparator();
// HTTPS support.
r = session.Get("https://httpbin.org/get");
std::cout << r->content() << std::endl;
#endif // WEBCC_ENABLE_SSL
} catch (const webcc::Error& error) {