You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#include <cassert>
|
|
#include <iostream>
|
|
|
|
#include "webcc/client_session.h"
|
|
#include "webcc/logger.h"
|
|
|
|
int main() {
|
|
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
|
|
|
webcc::ClientSession session;
|
|
session.set_connect_timeout(5);
|
|
session.set_read_timeout(5);
|
|
session.Accept("application/json");
|
|
|
|
webcc::ResponsePtr r;
|
|
|
|
try {
|
|
r = session.Send(webcc::RequestBuilder{}.
|
|
Get("http://httpbin.org/get").
|
|
Query("name", "Adam Gu", /*encode*/true).Date()
|
|
());
|
|
|
|
assert(r->status() == webcc::Status::kOK);
|
|
assert(!r->data().empty());
|
|
|
|
r = session.Send(webcc::RequestBuilder{}.
|
|
Post("http://httpbin.org/post").
|
|
Body("{'name'='Adam', 'age'=20}").Json().Utf8()
|
|
());
|
|
|
|
assert(r->status() == webcc::Status::kOK);
|
|
assert(!r->data().empty());
|
|
|
|
#if WEBCC_ENABLE_SSL
|
|
|
|
r = session.Send(webcc::RequestBuilder{}.
|
|
Get("https://httpbin.org/get")
|
|
());
|
|
|
|
assert(r->status() == webcc::Status::kOK);
|
|
assert(!r->data().empty());
|
|
|
|
#endif // WEBCC_ENABLE_SSL
|
|
|
|
} catch (const webcc::Error& error) {
|
|
std::cerr << error << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|