post with qt

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

    QNetworkAccessManager manager;

    QUrl url("");
    QNetworkRequest request(url);
    request.setRawHeader("Content-Type", "text/plain");
    QByteArray data("Hi");
    QNetworkReply *reply =, data);
        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 ''
    --header 'Content-Type: text/plain'
    --data-raw 'Hi'

  • Try out:

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

Log in to reply