相关文章推荐
茫然的筷子  ·  1-Python - 操作Excel文件 ...·  1 年前    · 
儒雅的机器猫  ·  Single-Cell ...·  2 年前    · 
眉毛粗的毛衣  ·  NodeJS 防止xss攻击 ...·  2 年前    · 
才高八斗的啄木鸟  ·  not in executable ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm attempting to make a POST request to a web page but I got a error in code below:

void WebViewModel::sendPOST(QString url)
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded"));
    QByteArray postData;
    postData.append("");
    manager_->post(request, postData);
    connect(manager_, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinishedSlot(QNetworkReply *)));
void WebViewModel::replyFinishedSlot(QNetworkReply *reply)
    QUrl webReportsUrl("http://...");
    if(reply->error())  <-- **Here I got NetworkReply::NetworkError(ProtocolInvalidOperationError)**
        qDebug() << "Error: ";
        qDebug() << reply->errorString();
        qDebug() << QNetworkReply::NetworkError(reply->error());
        qDebug() << reply->error();
        qDebug() << "no error";
    reply->deleteLater();

This is 302 error with a following description from QT documentation:

the requested operation is invalid for this protocol

How to fix?

This happens when server responds with 400 status code (Bad Request) or with 418 status code (I'm a teapot).

Either server is not configured properly, or it does not expect post requests to that endpoint, or it doesn't like requests with empty body.

You can use curl to validate that server responds with no error to post requests.

It could also be wrong values in the payload e.g. "password is too short" etc. Although the server can totally emit a different http status. In short, there is something wrong with the request/request data that the OP should address. – puerile Feb 22, 2022 at 7:47

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.