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.
–
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.