Hi,
am also facing the same issue . I want to separate the header and body . and am extracted the xml file using QNetworkReply only.
Anyone please help me by showing how to separate the header and body!!!
Hi,
am also facing the same issue . I want to separate the header and body . and am extracted the xml file using QNetworkReply only.
Anyone please help me by showing how to separate the header and body!!!
The headers are *already* separated from the response data when using QNetworkReply. You retrieve the body or response data by the QNetworkReply::read* methods or incrementally by connecting a slot to QNetworkReply::readyRead.
The headers are available via the QNetworkReply::rawHeader* methods.
Hi,
Thanks for the reply.
THis is my first project as a developer. Requesting you for the one more clarification.
Here is the question.
By using this below 1st piece of code I can read both header and body of the xml file.
1. QString data = (QString) pReply->readAll();
and by using this 2nd piece of code I can read only body of the xml file
2. QString data = (QString) pReply->readRead();
Does this my understanding this concept is correct.?
Please Find the below piece of code I have written for to pass the xml using http . my intention is to pass only the received xml
body to the function decoder .
void Uploader::upload(QString xmlFilePath)
{
qDebug() << "Upload Starting";
QFileInfo fileInfo(xmlFilePath);
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart filePart;
filePart.setHeader(QNetworkRequest::ContentDisposi tionHeader, QVariant("HTTP/1.1 200 OK"));
filePart.setHeader(QNetworkRequest::ContentTypeHea der, QVariant("text/xml; charset=utf-8"));
QFile *file = new QFile(xmlFilePath);
if ( !file->exists() )
{
qDebug() << "File Does not exist";
}
file->open(QIODevice::ReadOnly);
filePart.setBodyDevice(file);
file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
multiPart->append(filePart);
QUrl url("http://google.com");
QNetworkRequest request(url);
pManager = new QNetworkAccessManager();
pReply = pManager->post(request, multiPart);
multiPart->setParent(pReply);
QObject::connect(pReply, SIGNAL(QNetworkReply::finished()),this, SLOT(Uploader::uploadFinished()));
uploadInProgress = true;
uploadtoDecoder();
}
/**
* @brief Uploader::uploadFinished
*/
void Uploader::uploadFinished()
{
QString data = (QString) pReply->readAll();
qDebug() << data;
qDebug() << "Upload finished";
uploadInProgress = false;
if ( pReply->error() > 0 )
{
qDebug() << "Error occured: " << pReply->error() << " : " << pReply->errorString();
}
else
{
qDebug() << "Upload success";
}
pReply->deleteLater();
}
/**
* @brief Uploader::uploadToDecoder
*/
void Uploader::uploadToDecoder()
{
/* I have doubt here only */
QString datafull = (QString) pReply->readAll(); \\for to read both header and body
qDebug() << data;
QString data = (QString) pReply->readRead(); \\for to read only body
qDebug() << data;
decoder(data); // here i am passing the xml body only
.
.
.
.
.
}
Does my understanding is correct ????
In my experience with QNetworkReply, QNetworkReply::readAll() does not return header data. You'd have to show me output that contains headers and data for me to believe that...
Your 2nd example isn't even valid syntax, so no comment there, sorry. Show me where you receive headers *and* data when doing a readAll().
Bookmarks