我正在寻找对网页进行非常简单的POST请求.该页面位于php中,将采用发布的所有内容,将其对照数据库进行检查,如果该项目位于数据库中,则使用密钥进行响应.
I'm looking to do a very simple POST request to a webpage. The page is in php and will take whatever is posted check it against a database then respond with a key if the item is in the database.
我不知道如何在Qt中使用发布请求或如何获取返回的信息并将其存储回Qt中的变量中.任何帮助将不胜感激,因为我从Qt方面的空白开始.
I have not a clue how to use post requests inside Qt or how to get information returned and store it back into a variable within Qt. Any help would be highly appreciated as I am starting from a blank on the Qt side.
我看了其他例子:
stackoverflow/questions/11348359/qt-https-post-request
如何使用以下方法将数据发布到url QNetworkAccessManager
但是我看不到如何存储来自php脚本的响应
but I don't see how to store a response from the php script
推荐答案将完成的 QNetworkAccessManager 信号连接到插槽,并使用 QNetworkReply 阅读所有网页.
Connect the QNetworkAccessManager signal finished to your slot and using QNetworkReply you should read all the contents of the webpage.
这是一个获取示例,可以轻松地将其应用于post方法.
Here is a get example it can be easily adapted for the post method.
void MainWindow::on_pushButton_clicked() { QNetworkAccessManager * mgr = new QNetworkAccessManager(this); connect(mgr,SIGNAL(finished(QNetworkReply*)),this,SLOT(onfinish(QNetworkReply*))); connect(mgr,SIGNAL(finished(QNetworkReply*)),mgr,SLOT(deleteLater())); mgr->get(QNetworkRequest(QUrl("www.google"))); } void MainWindow::onfinish(QNetworkReply *rep) { QByteArray bts = rep->readAll(); QString str(bts); QMessageBox::information(this,"sal",str,"ok"); }更多推荐
Qt简单发布请求
发布评论