Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see you're trying to use QHTTP and QHttpRequestHeader classes. QT documentation says those are deprecated:</p> <blockquote> <p>This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.</p> </blockquote> <p>so, as it was suggested before; I would recommend using <a href="http://qt.nokia.com/doc/4.6/qnetworkaccessmanager.html" rel="nofollow noreferrer">QNetworkAccessManager</a> for what you're trying to do</p> <p>as for your original question; you still can use QHTTP to upload files; I believe actual request headers structure depends on the particular site you're trying to access. In this case tools like <a href="http://www.wireshark.org/" rel="nofollow noreferrer">wireshark</a> would be in great help. Pls, check if code below would work for you, it should upload test1.jpg file from the home folder and dump its link on the server if 302 response returned.</p> <pre><code>void MainWindow::on_pushButton_clicked() { http = new QHttp(this); // http declared as a member of MainWindow class connect(http, SIGNAL(requestFinished(int,bool)), SLOT(httpRequestFinished(int, bool))); QString boundary = "---------------------------723690991551375881941828858"; // action QByteArray data(QString("--" + boundary + "\r\n").toAscii()); data += "Content-Disposition: form-data; name=\"action\"\r\n\r\n"; data += "file_upload\r\n"; // file data += QString("--" + boundary + "\r\n").toAscii(); data += "Content-Disposition: form-data; name=\"sfile\"; filename=\"test1.jpg\"\r\n"; data += "Content-Type: image/jpeg\r\n\r\n"; QFile file("/home/test1.jpg"); if (!file.open(QIODevice::ReadOnly)) return; data += file.readAll(); data += "\r\n"; // password data += QString("--" + boundary + "\r\n").toAscii(); data += "Content-Disposition: form-data; name=\"password\"\r\n\r\n"; //data += "password\r\n"; // put password if needed data += "\r\n"; // description data += QString("--" + boundary + "\r\n").toAscii(); data += "Content-Disposition: form-data; name=\"description\"\r\n\r\n"; //data += "description\r\n"; // put description if needed data += "\r\n"; // agree data += QString("--" + boundary + "\r\n").toAscii(); data += "Content-Disposition: form-data; name=\"agree\"\r\n\r\n"; data += "1\r\n"; data += QString("--" + boundary + "--\r\n").toAscii(); QHttpRequestHeader header("POST", "/cabinet/upload/"); header.setValue("Host", "data.cod.ru"); header.setValue("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100401 Ubuntu/9.10 (karmic) Firefox/3.5.9"); header.setValue("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); header.setValue("Accept-Language", "en-us,en;q=0.5"); 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://data.cod.ru/"); //multipart/form-data; boundary=---------------------------723690991551375881941828858 header.setValue("Content-Type", "multipart/form-data; boundary=" + boundary); header.setValue("Content-Length", QString::number(data.length())); http-&gt;setHost("data.cod.ru"); http-&gt;request(header, data); file.close(); } void MainWindow::httpRequestFinished(int, bool) { QHttpResponseHeader responce = http-&gt;lastResponse(); if (responce.statusCode()==302) { qDebug() &lt;&lt; "file accepted; get it from:"; qDebug() &lt;&lt; "data.cod.ru" &lt;&lt; responce.value("Location"); } } </code></pre> <p>httpRequestFinished declared in the signals section of the MainWindow class</p> <p>hope this helps, privet ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload