Add an example for x-www-form-urlencoded
This commit is contained in:
@@ -34,6 +34,9 @@ target_link_libraries(server_states ${EXAMPLE_LIBS})
|
|||||||
add_executable(form_client form_client.cc)
|
add_executable(form_client form_client.cc)
|
||||||
target_link_libraries(form_client ${EXAMPLE_LIBS})
|
target_link_libraries(form_client ${EXAMPLE_LIBS})
|
||||||
|
|
||||||
|
add_executable(form_urlencoded_client form_urlencoded_client.cc)
|
||||||
|
target_link_libraries(form_urlencoded_client ${EXAMPLE_LIBS})
|
||||||
|
|
||||||
add_executable(form_server form_server.cc)
|
add_executable(form_server form_server.cc)
|
||||||
target_link_libraries(form_server ${EXAMPLE_LIBS})
|
target_link_libraries(form_server ${EXAMPLE_LIBS})
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// A client posting urlencoded form data.
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "webcc/client_session.h"
|
||||||
|
#include "webcc/logger.h"
|
||||||
|
|
||||||
|
namespace bfs = boost::filesystem;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||||
|
|
||||||
|
webcc::ClientSession session;
|
||||||
|
|
||||||
|
session.SetContentType("application/x-www-form-urlencoded", "utf8");
|
||||||
|
|
||||||
|
std::string url = "http://httpbin.org/post";
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Don't use RequestBuilder::Query() which is dedicated to GET.
|
||||||
|
webcc::UrlQuery query;
|
||||||
|
query.Add("key1", "value1");
|
||||||
|
query.Add("key2", "value2");
|
||||||
|
// ...
|
||||||
|
|
||||||
|
auto r = session.Send(
|
||||||
|
webcc::RequestBuilder{}.Post(url).Body(query.ToString())());
|
||||||
|
|
||||||
|
std::cout << r->data() << std::endl;
|
||||||
|
|
||||||
|
} catch (const webcc::Error& error) {
|
||||||
|
std::cout << error << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user