void Snipitron::connectS()
{
connect(http, SIGNAL(readyRead(const QHttpResponseHeader&)),
this, SLOT(readyRead(const QHttpResponseHeader&)));
http->setHost("www.example.com");
QString initialPath
= QDir::currentPath() + tr
("/unt.") + "jpeg";
userfile
= new QFile(initialPath
);
QString boundary
="-----------------------------AaB03x";
QString start_delim
="--"+boundary
+endline;
QString cont_disp_str
="Content-Disposition: form-data; ";
QString user_str
= start_delim
+ cont_disp_str
+ "name=" + "\"user\""+endline
+endline
+"arun"+endline;
data.
append(QString(user_str
).
toUtf8());
QString pass_str
= start_delim
+ cont_disp_str
+ "name=" + "\"pass\""+endline
+endline
+"1a27452283b0b46720913760f056377eb0b6388c"+endline;
data.
append(QString(pass_str
).
toUtf8());
QString proj_str
= start_delim
+ cont_disp_str
+ "name=" + "\"project_name\""+endline
+endline
+"Misc"+endline;
data.
append(QString(proj_str
).
toUtf8());
QString projId_str
= start_delim
+ cont_disp_str
+ "name=" + "\"project_id\""+endline
+endline
+"1951"+endline;
data.
append(QString(projId_str
).
toUtf8());
QString notes_str
= start_delim
+ cont_disp_str
+ "name=" + "\"title\""+endline
+endline
+"Test project add - Qt way"+endline;
data.
append(QString(notes_str
).
toUtf8());
QString title_str
= start_delim
+ cont_disp_str
+ "name=" + "\"uploadfile1\""+ ";filename=unt.jpeg" +endline
+ "Content-Type: image/jpeg" +endline
+endline;
title_str.append(userfile->readAll());
title_str = title_str + endline;
data.
append(QString(title_str
).
toUtf8());
userfile->close(); // the file is opened earlier in the code
QString v_str
= start_delim
+ cont_disp_str
+ "name=" + "\"v\""+endline
+endline
+"1.0"+endline;
//data.writeRawBytes(v_str.data(),v_str.length());
data.
append(QString(v_str
).
toUtf8());
QString cmd_str
= start_delim
+ cont_disp_str
+ "name=" + "\"command\""+endline
+endline
+"add"+endline;
//data.writeRawBytes(cmd_str.data(),cmd_str.length());
data.
append(QString(cmd_str
).
toUtf8());
QString stop_delim
="--"+boundary
+"--"+endline;
data.
append(QString(stop_delim
).
toUtf8());
header.setValue("Host", "www.example.com");
header.setContentType("multipart/form-data, boundary=-----------------------------AaB03x");
header.setContentLength(data.length());
http->request(header, data);
}
void Snipitron::connectS()
{
http = new QHttp(this);
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
connect(http, SIGNAL(readyRead(const QHttpResponseHeader&)),
this, SLOT(readyRead(const QHttpResponseHeader&)));
http->setHost("www.example.com");
QString initialPath = QDir::currentPath() + tr("/unt.") + "jpeg";
userfile = new QFile(initialPath);
QByteArray data,payLoad;
QString boundary="-----------------------------AaB03x";
QString endline="\r\n";
QString start_delim="--"+boundary+endline;
QString cont_disp_str="Content-Disposition: form-data; ";
QString user_str = start_delim + cont_disp_str + "name=" + "\"user\""+endline+endline+"arun"+endline;
data.append(QString(user_str).toUtf8());
QString pass_str = start_delim + cont_disp_str + "name=" + "\"pass\""+endline+endline+"1a27452283b0b46720913760f056377eb0b6388c"+endline;
data.append(QString(pass_str).toUtf8());
QString proj_str = start_delim + cont_disp_str + "name=" + "\"project_name\""+endline+endline+"Misc"+endline;
data.append(QString(proj_str).toUtf8());
QString projId_str = start_delim + cont_disp_str + "name=" + "\"project_id\""+endline+endline+"1951"+endline;
data.append(QString(projId_str).toUtf8());
QString notes_str = start_delim + cont_disp_str + "name=" + "\"title\""+endline+endline+"Test project add - Qt way"+endline;
data.append(QString(notes_str).toUtf8());
if (!userfile->open(QIODevice::ReadOnly))
QMessageBox::critical(this, "Arun", "File not found", QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
QString title_str = start_delim + cont_disp_str + "name=" + "\"uploadfile1\""+ ";filename=unt.jpeg" +endline + "Content-Type: image/jpeg" +endline+endline;
title_str.append(userfile->readAll());
title_str = title_str + endline;
data.append(QString(title_str).toUtf8());
userfile->close(); // the file is opened earlier in the code
QString v_str = start_delim + cont_disp_str + "name=" + "\"v\""+endline+endline+"1.0"+endline;
//data.writeRawBytes(v_str.data(),v_str.length());
data.append(QString(v_str).toUtf8());
QString cmd_str = start_delim + cont_disp_str + "name=" + "\"command\""+endline+endline+"add"+endline;
//data.writeRawBytes(cmd_str.data(),cmd_str.length());
data.append(QString(cmd_str).toUtf8());
QString stop_delim="--"+boundary+"--"+endline;
data.append(QString(stop_delim).toUtf8());
QHttpRequestHeader header("POST", "/app/submit.jsp");
header.setValue("Host", "www.example.com");
header.setContentType("multipart/form-data, boundary=-----------------------------AaB03x");
header.setContentLength(data.length());
QMessageBox::critical(this, "Arun", data, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
http->request(header, data);
}
To copy to clipboard, switch view to plain text mode
Bookmarks