Download *d1=new Download;d1->post("http://domain.ru/auth","Password="+password+"&Login="+mail);//Выполняетсяd1->load("http://domain.ru/welcome?p=finish");//ВыполняетсяQString ref=d1->load("http://domain.ru/"+login+"/i/420053");QRegExp rx2("'([0-9]{10})'");rx2.indexIn(ref);QString setup=d1->post("http://domain.ru/do","a=1&b=2&c="+rx2.cap(1));//Не выполняется на другом компьютереdelete d1;
void Download::getReplyFinished(){ reply->deleteLater();}void Download::readyReadReply(){ buffer = QString::fromUtf8(reply->readAll());}QString Download::load(QString url){ QNetworkRequest request; request.setUrl(QUrl(url)); reply=manager.get(request); connect(reply, SIGNAL(finished()), this, SLOT(getReplyFinished())); connect(reply,SIGNAL(readyRead()),this, SLOT(readyReadReply())); QEventLoop loop(this); connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); return buffer;}
#ifndef DOWNLOAD_H#define DOWNLOAD_H#include <QtNetwork/QNetworkAccessManager>#include <QtNetwork/QNetworkReply>#include <QtNetwork/QNetworkRequest>class Download : public QObject{ Q_OBJECTpublic: QString load(QString url);private: QString buffer; QNetworkAccessManager manager; QNetworkReply *reply; QString Url;public slots: void getReplyFinished(); void readyReadReply();};#endif // DOWNLOAD_H
QString setup=d1->post("http://domain.ru/do","a=1&b=2&c="+rx2.cap(1));//Не выполняется на другом компьютереdelete d1;
QString Download::post(QString url,QString post){ QNetworkRequest request; request.setUrl(QUrl(url)); request.setRawHeader(QByteArray("User-Agent"), QByteArray("User-Agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.12) Gecko/20101026 MRA 5.6 (build 03402) Firefox/3.6.12 GTB7.1")); reply=manager.post(request,post.toUtf8()); connect(reply, SIGNAL(finished()), this, SLOT(getReplyFinished())); connect(reply,SIGNAL(readyRead()),this, SLOT(readyReadReply())); QEventLoop loop(this); connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); return buffer;}
connect(reply, SIGNAL(finished()), this, SLOT(getReplyFinished()));connect(reply,SIGNAL(readyRead()),this, SLOT(readyReadReply()));
QString Download::post(QString url,QString post){ QNetworkRequest request; request.setUrl(QUrl(url)); request.setRawHeader(QByteArray("User-Agent"), QByteArray("User-Agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.12) Gecko/20101026 MRA 5.6 (build 03402) Firefox/3.6.12 GTB7.1")); reply=manager.post(request,post.toUtf8()); //connect(reply, SIGNAL(finished()), this, SLOT(getReplyFinished())); //connect(reply,SIGNAL(readyRead()),this, SLOT(readyReadReply())); QEventLoop loop(this); connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); buffer = QString::fromUtf8(reply->readAll()); return buffer;}