How to Keep-Alive Connection calling rest Web Service
It is necessary to keep alive any TCP/HTTP while calling 2 or more Server request if so
how to use connection:Keep-Alive , Im using that codes below:
#include <QDebug>
#include <QThread>
#include <QtCore/QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkProxy>
#include <QtXml/QDomDocument>
MainWindow
::MainWindow(QWidget *parent,
) :ui(new Ui::afterbarcode)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString url
="http://127.0.0.1:8085/";
QString Webmethod
="ValidationRequest?SessionKey=12345678";
QString REQUEST_URL
=url
+Webmethod;
m_network = new QNetworkAccessManager (this);
QNetworkRequest request;
request.
setUrl(QUrl(REQUEST_URL
));
QNetworkReply *reply = m_network->get(request);
QObject::connect(m_network,
SIGNAL(finished
(QNetworkReply
*)),
SLOT(RequestFinished(QNetworkReply *)));
}
void MainWindow::RequestFinished(QNetworkReply *reply){
doc.setContent(data);
qDebug()<<"<XML>"<<doc.toString()<<"</XML>";
QDomNodeList ValidationResponse
= doc.
elementsByTagName("ValidationResponse");
#include <QDebug>
#include <QThread>
#include <QtCore/QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkProxy>
#include <QtXml/QDomDocument>
MainWindow::MainWindow(QWidget *parent,) :
QDialog(parent),
ui(new Ui::afterbarcode)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString url="http://127.0.0.1:8085/";
QString Webmethod="ValidationRequest?SessionKey=12345678";
QString REQUEST_URL =url+Webmethod;
m_network = new QNetworkAccessManager (this);
QNetworkRequest request;
request.setUrl(QUrl(REQUEST_URL));
QNetworkReply *reply = m_network->get(request);
QObject::connect(m_network, SIGNAL(finished(QNetworkReply *)),
SLOT(RequestFinished(QNetworkReply *)));
}
void MainWindow::RequestFinished(QNetworkReply *reply){
QByteArray data = reply->readAll();
QDomDocument doc;
doc.setContent(data);
qDebug()<<"<XML>"<<doc.toString()<<"</XML>";
QDomNodeList ValidationResponse = doc.elementsByTagName("ValidationResponse");
QDomNodeList Result = doc.elementsByTagName("Result");
To copy to clipboard, switch view to plain text mode
Bookmarks