Qt简单发布请求

编程入门 行业动态 更新时间:2024-10-28 19:35:20
本文介绍了Qt简单发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找对网页进行非常简单的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简单发布请求

本文发布于:2023-10-11 17:56:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1482414.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   Qt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!