QHttp *http = new QHttp( this );QsslSocket *ssl = new QsslSocket( this );http->setSocket( ssl );
/******************************************************************************** Copyright (C) 2007 Urs Wolfer <uwolfer @ fwo.ch>**** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU Library General Public License** along with this library; see the file COPYING.LIB. If not, write to** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,** Boston, MA 02110-1301, USA.******************************************************************************/ #include <QHttp>#include <QByteArray>#include <QFile>#include <QTextStream>#include <QDebug> #include "smssender.h" SmsSender::SmsSender(QObject *parent) : QObject(parent){ http = new QHttp("idn.ethz.ch", QHttp::ConnectionModeHttps, 0, this); connect(http, SIGNAL(requestFinished(int,bool)), SLOT(slotFinished(int,bool))); connect(http, SIGNAL(stateChanged(int)), SLOT(slotChanged(int))); http->get("/cgi-bin/sms/main.cgi/iibfgipqmqnntvvrqsps/_top"); } void SmsSender::login(){ QByteArray parms(""); parms.clear(); parms.append("_login_page=1"); parms.append("&"+ loginLogin+"=Login"); parms.append("&_username=psoukal"); parms.append("&"+ loginPw+"=guetetagwohl"); http->post("/cgi-bin/sms/main.cgi/" + loginUrl + "/_top", parms); parms.clear(); parms.append("originator=text"); parms.append("&textoriginator=TEst"); parms.append("&phone=0798103355"); parms.append("&messagetext=hallo%20test"); parms.append("&send=Send"); http->post("/cgi-bin/sms/task1.fastpl/psoukal_" + loginUrl + "/_top", parms); } void SmsSender::slotChanged(int id){// qDebug(error ? "error" : "ok");// qDebug(qPrintable(QString::number((int)http->error())));// qDebug(qPrintable(http->readAll()));// qDebug("changed");// qDebug(qPrintable(QString::number(id)));// qDebug(http->readAll());} void SmsSender::slotFinished(int id, bool error){ qDebug(error ? "error" : "ok"); qDebug(qPrintable(QString::number((int)http->error())));// qDebug(qPrintable(http->readAll())); qDebug(qPrintable(QString::number(id)));// qDebug(http->readAll());// QString output(http->readAll().data()); if (id == 2) qDebug(http->readAll().data()); if (id == 3) qDebug(http->readAll().data()); if (id == 1) {// qDebug(http->readAll().data()); QString output(http->readAll().data()); int j = 0; while ((j = output.indexOf("main.cgi", j)) != -1) {// qDebug() << "Found <b> tag at index position" << j; ++j; QString o1 = output.right(output.length() - j -8); o1 = o1.left(20); loginUrl = o1; qDebug(o1.toLatin1().data()); } j = 0; while ((j = output.indexOf("tabindex=\"1\" name=", j)) != -1) {// qDebug() << "Found <b> tag at index position" << j; ++j; QString o1 = output.right(output.length() - j -18); o1 = o1.left(8); loginLogin = o1; qDebug(o1.toLatin1().data()); } j = 0; while ((j = output.indexOf("type=\"password\" name=", j)) != -1) {// qDebug() << "Found <b> tag at index position" << j; ++j; QString o1 = output.right(output.length() - j -21); o1 = o1.left(8); loginPw = o1; qDebug(o1.toLatin1().data()); } login();} }