Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QHttpMultiPart don't work
Qt 6.11 is out! See what's new in the release blog

QHttpMultiPart don't work

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ARASHz4
    wrote on last edited by ARASHz4
    #1

    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\""));
        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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

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

        A Offline
        A Offline
        ARASHz4
        wrote on last edited by
        #3

        @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
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved