// file init
//inputFile.setFileName("test.csv");
inputFile.setFileName("main.cpp");
if(!inputFile.
open(QFile::ReadOnly|QIODevice
::Text)) { ui->textEdit->append("File failed to open - contact system administrator.");
} else {
QString boundary,data,crlf,fileByteSize;
boundary="-----------------------------7d935033608e2";
crlf=0x0d;
crlf+=0x0a;
data=crlf+"--"+boundary+crlf; // start delimiter
data+="Content-Disposition: form-data; name=\"MAX_FILE_SIZE\";"+crlf+crlf;
data+=fileByteSize.setNum(inputFile.size()+1);
data+=crlf+"--"+boundary+crlf;
data+="Content-Disposition: form-data; name=\"username\";"+crlf+crlf+"username"+crlf; // !! effect username !!
data+=crlf+"--"+boundary+crlf;
data+="Content-Disposition: form-data; name=\"password\";"+crlf+crlf+"password"+crlf; // !! effect password !!
data+=crlf+"--"+boundary+crlf;
data+="Content-Disposition: form-data; name=\"uploadedFile\"; filename=\"ContactList.csv\";"+crlf;
data+="Content-Type: text/plain"+crlf+crlf+inputFile.readAll()+crlf;
data+="--"+boundary+"--"+crlf; // stop delimiter
dataToSend.insert(0,data); // convert to byte array for request
ui->textEdit->insertPlainText(dataToSend.data()); // update ui for my own sake
// request init
QNetworkRequest request
(QUrl("http://edm.localhost/uploader.php"));
//request.setRawHeader("Content Type","text/plain");
//QString contentType="multipart/form-data; boundary=\""+boundary+"\"";
//QString host="http://edm.localhost/";
//request.setRawHeader("Host",host.toAscii());
// if (userAgentS!="") request.setRawHeader("User-Agent", userAgentS.toAscii());
// if (refererS!="") request.setRawHeader("Referer", refererS.toAscii());
//request.setHeader(QNetworkRequest::ContentTypeHeader,contentType.toAscii());
//request.setHeader(QNetworkRequest::ContentLengthHeader,QVariant(inputFile.size()).toString());
//request.setUrl(QUrl("http://edm.localhost"));
//request.setRawHeader("Content Disposition","form-data; name=\"uploadedFile\"; filename=\"DownloadedContactList.csv\"");
//request.setRawHeader("Content Length",dataToSend);//fileByteSize.setNum(inputFile.size()));
//request.setHeader(QNetworkRequest::ContentTypeHeader,"multipart/form-data; boundary: -----------------------------7d935033608e2\n");
request.setHeader(QNetworkRequest::ContentLengthHeader,inputFile.size());
reply=manager.post(request,dataToSend); // perform post request
// QByteArray data = reply->readAll();
// QTextStream out(&data);
// QString file = out.readAll();
ui->textEdit->append(reply->readAll());
// connections
connect(reply,SIGNAL(uploadProgress(qint64,qint64)),SLOT(mySetValue(qint64,qint64)));
connect(reply,SIGNAL(finished()),SLOT(replyFinished())); // reply finished - close file
// file init
//inputFile.setFileName("test.csv");
inputFile.setFileName("main.cpp");
if(!inputFile.open(QFile::ReadOnly|QIODevice::Text)) {
ui->textEdit->append("File failed to open - contact system administrator.");
} else {
QString boundary,data,crlf,fileByteSize;
QByteArray dataToSend;
boundary="-----------------------------7d935033608e2";
crlf=0x0d;
crlf+=0x0a;
data=crlf+"--"+boundary+crlf; // start delimiter
data+="Content-Disposition: form-data; name=\"MAX_FILE_SIZE\";"+crlf+crlf;
data+=fileByteSize.setNum(inputFile.size()+1);
data+=crlf+"--"+boundary+crlf;
data+="Content-Disposition: form-data; name=\"username\";"+crlf+crlf+"username"+crlf; // !! effect username !!
data+=crlf+"--"+boundary+crlf;
data+="Content-Disposition: form-data; name=\"password\";"+crlf+crlf+"password"+crlf; // !! effect password !!
data+=crlf+"--"+boundary+crlf;
data+="Content-Disposition: form-data; name=\"uploadedFile\"; filename=\"ContactList.csv\";"+crlf;
data+="Content-Type: text/plain"+crlf+crlf+inputFile.readAll()+crlf;
data+="--"+boundary+"--"+crlf; // stop delimiter
dataToSend.insert(0,data); // convert to byte array for request
ui->textEdit->insertPlainText(dataToSend.data()); // update ui for my own sake
// request init
QNetworkRequest request(QUrl("http://edm.localhost/uploader.php"));
//request.setRawHeader("Content Type","text/plain");
//QString contentType="multipart/form-data; boundary=\""+boundary+"\"";
//QString host="http://edm.localhost/";
//request.setRawHeader("Host",host.toAscii());
// if (userAgentS!="") request.setRawHeader("User-Agent", userAgentS.toAscii());
// if (refererS!="") request.setRawHeader("Referer", refererS.toAscii());
//request.setHeader(QNetworkRequest::ContentTypeHeader,contentType.toAscii());
//request.setHeader(QNetworkRequest::ContentLengthHeader,QVariant(inputFile.size()).toString());
//request.setUrl(QUrl("http://edm.localhost"));
//request.setRawHeader("Content Disposition","form-data; name=\"uploadedFile\"; filename=\"DownloadedContactList.csv\"");
//request.setRawHeader("Content Length",dataToSend);//fileByteSize.setNum(inputFile.size()));
//request.setHeader(QNetworkRequest::ContentTypeHeader,"multipart/form-data; boundary: -----------------------------7d935033608e2\n");
request.setHeader(QNetworkRequest::ContentLengthHeader,inputFile.size());
reply=manager.post(request,dataToSend); // perform post request
// QByteArray data = reply->readAll();
// QTextStream out(&data);
// QString file = out.readAll();
ui->textEdit->append(reply->readAll());
// connections
connect(reply,SIGNAL(uploadProgress(qint64,qint64)),SLOT(mySetValue(qint64,qint64)));
connect(reply,SIGNAL(finished()),SLOT(replyFinished())); // reply finished - close file
To copy to clipboard, switch view to plain text mode
Bookmarks