Unsolved QHttpMultiPart don't work
-
Hi
I want send a message to telegram bot with http post
this is my codeQHttpMultiPart *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\"")); textPart1.setBody(QString("@user").toUtf8()); 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()); multiPart->append(textPart1); multiPart->append(textPart2); QUrl url("https://api.telegram.org/bot" + token + "/sendMessage"); QNetworkRequest request(url); QNetworkAccessManager manager; QNetworkReply *reply = manager.post(request, multiPart); multiPart->setParent(reply);
This don't work
This a bug in Qt or my code have a problem? -
Hi,
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 https://api.telegram.org/botToken/sendMessage - server replied: Bad Request
-
Did you check whether the answer contained more information about the error ? See here for possible causes.