void Gui_Upload::BeginnJob()
{
bool method_1 = true;
const uint MAXWAITING = timer2.addSecs(8).toTime_t();
qDebug() << "### POSTID " << POSTID;
QString posturl
= "http://ppk.go/qt/tools.php?id=test";
if (us.size() < 1 or pa.size() < 1) {
QMessageBox::information(this, tr
("HTTP"),tr
("User Name or Pass not set!"));
return;
}
qDebug() << "### user " << us;
qDebug() << "### pass " << pa;
pushButton->setEnabled(false);
QString fileName
= QFileDialog::getOpenFileName(this,tr
("OpenFile"),openFilesPath,tr
("All Files (*);;Text Files (*.txt)"));
if (!fileName.isEmpty()) {
qDebug() << "### fileName " << fileName;
}
/* dear qt set and splitt the url self */
qDebug() << "### host " << url.host();
qDebug() << "### path " << url.path();
header.setValue("Host",url.host());
header.setValue("User-Agent", "QT4 4.1.3 QHttp troll method 1");
header.setValue("Accept", "text/plain");
header.setValue("Accept-Language", "en-us");
header.setValue("Accept-Encoding", "gzip,deflate");
header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
header.setValue("Keep-Alive", "300");
header.setValue("Connection", "keep-alive");
header.setValue("Referer", "http://ppk.go/qt/tools.php");
header.setValue("Content-Type", "multipart/form-data; boundary=---------------------------"+POSTID);
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"action\"\r\n");
bytes.append("beamup\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"submit\"\r\n");
bytes.append("Upload\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"username\"\r\n");
bytes.append(us+"\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"password\"\r\n");
bytes.append(pa+"\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"unixtime\"\r\n");
bytes.
append(QString::number(MAXWAITING
)+"\r\n");
if (method_1) {
qDebug() << "### METHOD 1 start ++++++++++++++++++++ ";
file->setFileName(fileName);
dateiName = fileInfo.fileName();
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"qtfile\"; filename=\""+dateiName+"\"\n");
bytes.
append("Content-length: " + QString::number(fileInfo.
size()));
bytes.append("\nContent-Type: text/plain\n\n");
bytes.append(file->readAll());
header.
setValue("Content-Length",
QString::number(fileInfo.
size()));
http_0
= new QHttp(url.
host(),
80,
this);
httpGetId = http_0->request(header, bytes);
qDebug() << "### post httpGetId " << httpGetId;
connect(http_0, SIGNAL(done(bool)), this, SLOT(FinishStream()));
connect(http_0, SIGNAL(dataSendProgress(int,int)), this, SLOT(WriteNowProgress(int,int)));
file->close();
qDebug() << "### METHOD 1 end ++++++++++++++++++++ ";
} else {
qDebug() << "### METHOD 2 start ++++++++++++++++++++ ";
qDebug() << "### host " << www.host();
qDebug() << "### path " << www.path();
http->setHost(www.host());
connect(http, SIGNAL(done(bool)), this, SLOT(FinishStream()));
http->post(www.path(), file);
qDebug() << "### METHOD 2 end ++++++++++++++++++++ ";
}
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
}
void Gui_Upload::BeginnJob()
{
bool method_1 = true;
QString openFilesPath = "/";
QDateTime timer2( QDateTime::currentDateTime() );
const uint MAXWAITING = timer2.addSecs(8).toTime_t();
const QString POSTID = QString( "11478%1\r\n" ).arg( QString::number(MAXWAITING) );
const QString POSTIDEND = QString( "11478%1--\r\n" ).arg( QString::number(MAXWAITING) );
qDebug() << "### POSTID " << POSTID;
QString us = username->text();
QString pa = pass->text();
QString posturl = "http://ppk.go/qt/tools.php?id=test";
if (us.size() < 1 or pa.size() < 1) {
QMessageBox::information(this, tr("HTTP"),tr("User Name or Pass not set!"));
return;
}
qDebug() << "### user " << us;
qDebug() << "### pass " << pa;
pushButton->setEnabled(false);
QString fileName = QFileDialog::getOpenFileName(this,tr("OpenFile"),openFilesPath,tr("All Files (*);;Text Files (*.txt)"));
if (!fileName.isEmpty()) {
qDebug() << "### fileName " << fileName;
}
/* dear qt set and splitt the url self */
QUrl url(posturl);
qDebug() << "### host " << url.host();
qDebug() << "### path " << url.path();
QHttpRequestHeader header("POST",url.path());
header.setValue("Host",url.host());
header.setValue("User-Agent", "QT4 4.1.3 QHttp troll method 1");
header.setValue("Accept", "text/plain");
header.setValue("Accept-Language", "en-us");
header.setValue("Accept-Encoding", "gzip,deflate");
header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
header.setValue("Keep-Alive", "300");
header.setValue("Connection", "keep-alive");
header.setValue("Referer", "http://ppk.go/qt/tools.php");
header.setValue("Content-Type", "multipart/form-data; boundary=---------------------------"+POSTID);
QByteArray bytes;
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"action\"\r\n");
bytes.append("beamup\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"submit\"\r\n");
bytes.append("Upload\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"username\"\r\n");
bytes.append(us+"\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"password\"\r\n");
bytes.append(pa+"\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"unixtime\"\r\n");
bytes.append(QString::number(MAXWAITING)+"\r\n");
if (method_1) {
qDebug() << "### METHOD 1 start ++++++++++++++++++++ ";
QString dateiName;
file = new QFile();
QFileInfo fileInfo(fileName);
file->setFileName(fileName);
dateiName = fileInfo.fileName();
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"qtfile\"; filename=\""+dateiName+"\"\n");
bytes.append("Content-length: " + QString::number(fileInfo.size()));
bytes.append("\nContent-Type: text/plain\n\n");
bytes.append(file->readAll());
header.setValue("Content-Length", QString::number(fileInfo.size()));
http_0 = new QHttp(url.host(),80,this);
httpGetId = http_0->request(header, bytes);
qDebug() << "### post httpGetId " << httpGetId;
connect(http_0, SIGNAL(done(bool)), this, SLOT(FinishStream()));
connect(http_0, SIGNAL(dataSendProgress(int,int)), this, SLOT(WriteNowProgress(int,int)));
file->close();
qDebug() << "### METHOD 1 end ++++++++++++++++++++ ";
} else {
qDebug() << "### METHOD 2 start ++++++++++++++++++++ ";
QUrl www(posturl);
qDebug() << "### host " << www.host();
qDebug() << "### path " << www.path();
QHttp *http = new QHttp(this);
http->setHost(www.host());
QFile *file = new QFile(fileName, http);
file->open(QIODevice::ReadOnly);
connect(http, SIGNAL(done(bool)), this, SLOT(FinishStream()));
http->post(www.path(), file);
qDebug() << "### METHOD 2 end ++++++++++++++++++++ ";
}
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
}
To copy to clipboard, switch view to plain text mode
Bookmarks