Qt简单发布请求 [英] Qt Simple Post Request

查看:109
本文介绍了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.

我看了其他例子:

https://stackoverflow.com/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("http://www.google.com")));

}

void MainWindow::onfinish(QNetworkReply *rep)
{
    QByteArray bts = rep->readAll();
    QString str(bts);
    QMessageBox::information(this,"sal",str,"ok");

}

这篇关于Qt简单发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆