Qt post http请求使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt post http请求使用相关的知识,希望对你有一定的参考价值。

#include "mainwindow.h" #include "ui_mainwindow.h" //#include "datadboperation.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString strUserInfo = QString("name=%1&password=%2").arg(user).arg(passward); QByteArray content = strUserInfo.toUtf8(); int contentLength = content.length(); QNetworkRequest netReq; netReq.setUrl(QUrl("server ip address")); netReq.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); netReq.setHeader(QNetworkRequest::ContentLengthHeader, contentLength); // 将用户名和密码发送至web服务器进行验证 networkAccessManager = new QNetworkAccessManager(this); // 发送参数 networkAccessManager->post(netReq, content); connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(SltLoginReplay(QNetworkReply*))); } void MainWindow::SltLoginReplay(QNetworkReply *reply) { int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug() << "statusCode:" << statusCode; if(reply->error() == QNetworkReply::NoError) { qDebug() << reply->readAll(); } else { qDebug() << "========="; } // At the end of that slot, we won‘t need it anymore reply->deleteLater(); } MainWindow::~MainWindow() { delete ui; }

以上是关于Qt post http请求使用的主要内容,如果未能解决你的问题,请参考以下文章

如何使用Qt进行post get模拟登录

如何使用Qt进行post get模拟登录

QNetworkAccessManager 未发送 POST 请求的数据部分

如何在qt应用程序中保存http会话

http请求头大数据post如何判断完整

QT https post请求(QNetworkRequest要设置SSL证书,而SSL证书认证有三种,实测成功)