码迷,mamicode.com
首页 > Web开发 > 详细

Qt post http请求使用

时间:2018-05-05 17:19:41      阅读:1636      评论:0      收藏:0      [点我收藏+]

标签:qt post

#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

原文地址:http://blog.51cto.com/whylinux/2113027

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!