1 /*=============================================================================
2 sample_add_client_complex.cpp
3 ===============================================================================
4 This is an example of an XML-RPC client that uses XML-RPC for C/C++
7 In particular, it uses the complex lower-level interface that gives you
8 lots of flexibility but requires lots of code. Also see
9 xmlrpc_sample_add_server, which does the same thing as this program,
10 but with much simpler code because it uses a simpler facility of
13 This program actually gains nothing from using the more difficult
14 facility. It is for demonstration purposes.
15 =============================================================================*/
21 #include <xmlrpc-c/girerr.hpp>
22 #include <xmlrpc-c/base.hpp>
23 #include <xmlrpc-c/client.hpp>
28 main(int argc, char **) {
31 cerr << "This program has no arguments" << endl;
36 xmlrpc_c::clientXmlTransport_curl myTransport(
37 xmlrpc_c::clientXmlTransport_curl::constrOpt()
38 .no_ssl_verifyhost(true)
39 .user_agent("sample_add/1.0"));
41 xmlrpc_c::client_xml myClient(&myTransport);
43 string const methodName("sample.add");
45 xmlrpc_c::paramList sampleAddParms;
46 sampleAddParms.add(xmlrpc_c::value_int(5));
47 sampleAddParms.add(xmlrpc_c::value_int(7));
49 xmlrpc_c::rpcPtr myRpcP(methodName, sampleAddParms);
51 string const serverUrl("http://localhost:8080/RPC2");
53 xmlrpc_c::carriageParm_curl0 myCarriageParm(serverUrl);
55 myRpcP->call(&myClient, &myCarriageParm);
57 assert(myRpcP->isFinished());
59 int const sum(xmlrpc_c::value_int(myRpcP->getResult()));
60 // Assume the method returned an integer; throws error if not
62 cout << "Result of RPC (sum of 5 and 7): " << sum << endl;
64 } catch (girerr::error const error) {
65 cerr << "Client threw error: " << error.what() << endl;
67 cerr << "Client threw unexpected error." << endl;