QNetworkAccessManager can not post multipart data



  • I use QNetworkAccessManager to upload file to my server. But sometimes QNetworkAccessManager did not post any data at all according to wireshark monitor. My code is as follows:
    @
    QHttpMultiPart *pMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
    for (QHash<QString, QPair<GString, GString>>::const_iterator iter = fileList.cbegin(); iter != fileList.cend(); ++iter)
    {
    QHttpPart oFilePart;
    oFilePart.setHeader(QNetworkRequest::LocationHeader, QVariant(iter.value().first));
    oFilePart.setHeader(QNetworkRequest::ContentDispositionHeader,
    GString("form-data; name="file"; filename="%1"").arg(iter.key()));
    oFilePart.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
    QFile *pfile = new QFile(iter.key());
    pfile->open(QIODevice::ReadOnly);
    oFilePart.setBodyDevice(pfile);
    pfile->setParent(pMultiPart);
    pMultiPart->append(oFilePart);
    }

    QUrl oURL(m_sURL);
    QNetworkRequest oRequest(oURL);
    QNetworkReply *pReply = m_pNetWorkAccessManager->post(oRequest, pMultiPart);
    pMultiPart->setParent(pReply);
    if (waitForReplyFinished(pReply))
    {
        bool bRet = pReply->error() == QNetworkReply::NoError;
        pReply->deleteLater();
        return bRet;
    }
    else
    {
        return false;
    }
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.