Important: Please read the Qt Code of Conduct -

QHttpMultiPart don't work

  • Hi
    I want send a message to telegram bot with http post
    this is my code

        QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
        QHttpPart textPart1;
        textPart1.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded"));
        textPart1.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; text=\"chat_id\""));
        QHttpPart textPart2;
        textPart2.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded"));
        textPart2.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; text=\"text\""));
        textPart2.setBody(QString("my text").toUtf8());
        QUrl url("" + token + "/sendMessage");
        QNetworkRequest request(url);
        QNetworkAccessManager manager;
        QNetworkReply *reply =, multiPart);

    This don't work
    This a bug in Qt or my code have a problem?

  • Lifetime Qt Champion


    There's no code related to error checking. You should connect the QNetworkReply::error signal to get more information about what is happening.

  • @SGaist i connect the QNetworkReply::error signal

    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError)));

    Error is :

    Error transferring - server replied: Bad Request

  • Lifetime Qt Champion

    Did you check whether the answer contained more information about the error ? See here for possible causes.

Log in to reply