Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. post with qt

post with qt

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 426 Views
  • 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
    Amanda0211
    wrote on last edited by
    #1

    Hi
    I am trying to make a post using qt with the following code:

    QNetworkAccessManager manager;

    QUrl url("http://192.168.4.1/post");
    QNetworkRequest request(url);
    
    request.setRawHeader("Content-Type", "text/plain");
    
    QByteArray data("Hi");
    QNetworkReply *reply = manager.post(request, data);
    
    if(reply->error()){
        qDebug() << reply->errorString();
    }
    
    connect(reply, &QIODevice::readyRead, this, [=] {
        qDebug() << "Reply: " << reply->readAll();
    });
    

    The thing is that my server don't reply so i don´t know if I am posting with a incorrect format or if it is another problem.

    When I use postman it works just fine!

    The curl code with postman is this one:
    curl --location --request POST 'http://192.168.4.1/post'
    --header 'Content-Type: text/plain'
    --data-raw 'Hi'

    1 Reply Last reply
    0
    • LematL Offline
      LematL Offline
      Lemat
      wrote on last edited by Lemat
      #2

      Try out:

      QUrl url("http://192.168.4.1/post");
      QNetworkRequest request(url);
      
      request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
      
      QUrlQuery urlq;
      urlq.addQueryItem ("Hi", "");
      
      QNetworkReply *reply = manager.post(request, urlq.toString (QUrl::FullyEncoded).toUtf8 ());
      
      while (!reply->isFinished())
      {
      	qApp->processEvents();
      }
      
      if(reply->error ()) qDebug ()<<reply->error();
      else qDebug ()<<reply->readAll();
      
      reply->deleteLater ();
      
      

      Time to elevate.

      1 Reply Last reply
      1

      • Login

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