| 1 | #include "client.h" |
| 2 | |
| 3 | Client::Client(QObject* parent) : QObject(parent) { |
| 4 | // rpc = new MaiaXmlRpcClient(QUrl("http://phpxmlrpc.sourceforge.net/server.php"), this); |
| 5 | // rpc = new MaiaXmlRpcClient(QUrl("https://rpc.gandi.net/xmlrpc/2.0/"), this); |
| 6 | rpc = new MaiaXmlRpcClient(QUrl("http://localhost:8082/RPC2"), this); |
| 7 | |
| 8 | QSslConfiguration config = rpc->sslConfiguration(); |
| 9 | config.setProtocol(QSsl::AnyProtocol); |
| 10 | rpc->setSslConfiguration(config); |
| 11 | |
| 12 | connect(rpc, SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &)), |
| 13 | this, SLOT(handleSslErrors(QNetworkReply *, const QList<QSslError> &))); |
| 14 | doClient(); |
| 15 | } |
| 16 | |
| 17 | void Client::doClient() { |
| 18 | QVariantList args; |
| 19 | rpc->call("examples.nix", args, |
| 20 | this, SLOT(testResponse(QVariant &)), |
| 21 | this, SLOT(testFault(int, const QString &))); |
| 22 | args << QVariant(7); |
| 23 | rpc->call("examples.getStateName", args, |
| 24 | this, SLOT(testResponse(QVariant &)), |
| 25 | this, SLOT(testFault(int, const QString &))); |
| 26 | rpc->call("examples.birne", args, |
| 27 | this, SLOT(testResponse(QVariant &)), |
| 28 | this, SLOT(testFault(int, const QString &))); |
| 29 | args[0] = QVariant(-128); |
| 30 | rpc->call("examples.birne", args, |
| 31 | this, SLOT(testResponse(QVariant &)), |
| 32 | this, SLOT(testFault(int, const QString &))); |
| 33 | rpc->call("examples.notfound", args, |
| 34 | this, SLOT(testResponse(QVariant &)), |
| 35 | this, SLOT(testFault(int, const QString &))); |
| 36 | QDateTime towelDay; |
| 37 | towelDay.setDate(QDate(2008, 5, 25)); |
| 38 | args.clear(); |
| 39 | args << towelDay; |
| 40 | rpc->call("examples.plusOneYear", args, |
| 41 | this, SLOT(towelResponse(QVariant &)), |
| 42 | this, SLOT(testFault(int, const QString &))); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | void Client::testResponse(QVariant &arg) { |
| 47 | qDebug() << arg.toString(); |
| 48 | } |
| 49 | |
| 50 | void Client::testFault(int error, const QString &message) { |
| 51 | qDebug() << "EEE:" << error << "-" << message; |
| 52 | } |
| 53 | |
| 54 | void Client::towelResponse(QVariant &arg) { |
| 55 | qDebug() << "Next years Towel Day is on" << arg.toDateTime(); |
| 56 | } |
| 57 | |
| 58 | void Client::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors) { |
| 59 | qDebug() << "SSL Error:" << errors; |
| 60 | reply->ignoreSslErrors(); // don't do this in real code! Fix your certs! |
| 61 | } |
| 62 |