Qt World Summit: Submit your Presentation

QNetworkManager Http Post binary file - error connection closed

  • hello,

    I am using QNetworkManager to post a binary file on a server. I can post an Xml file , but when I try to post the binary file , I don't get any response from server and the reply's error is connection closed.

    here some snippet of my code:

    QNetworkRequest lQNetworkRequest;
    QNetworkRequest.setUrl(QUrl ("http://10.0.x.X/cgi-bin/file.cgi"));
    lQNetworkRequest.setHeader (QNetworkRequest::ContentDispositionHeader, "form-data;name=\"file\";filename=\"MYFILE.bin\"");
    lQNetworkRequest.setHeader (QNetworkRequest::ContentTypeHeader, "application/binary");
    aFile = new QFile ("MYFILE.bin");
    aFile->open (QIODevice::ReadOnly)
    aNetworkReply = aQnam->post(kpQNetworkRequest, aFile);
    connect(aNetworkReply , SIGNAL(finished()), this, SLOT(mvHttpFinished()))
    connect(aNetworkReply , SIGNAL(readyRead()), this, SLOT(mvHttpReadyRead()))

    My function mvHttpFinished is called and I got the aNetworkReply->error = 2 = Connection closed.

    Maybe I miss some important information in the header ? I am not about the ContentTypeHeader . I saw you can use application/octet-stream

    anyone can help me?

  • Lifetime Qt Champion

    Since we don't know what your server needs we can't really help here.

Log in to reply