I have the following code, and I would like to add some HTTP header info along with the call. Anyway that I can do that?
void NeoAPI::call(QString apiCall) {
if (this->ApiCall.contains(apiCall)) {
QNetworkAccessManager* manager = new QNetworkAccessManager(0);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(netReplyFinished(QNetworkReply*)));
QUrl url = this->ApiCall[apiCall];
url.addQueryItem("memberid","76710"); // Set for backdoor debugging
manager->get(QNetworkRequest(url));
} else {
this->requestResultText = QString("Call %1 doesn't exist").arg(apiCall);
}
}
void NeoAPI::netReplyFinished(QNetworkReply *netReply) {
if (netReply->error() == QNetworkReply::NoError) {
this->requestResultText = netReply->readAll();
} else {
this->requestResultText = "API Call Failed";
}
QMessageBox messageBox;
messageBox.setText(this->requestResultText);
messageBox.exec();
//delete netReply;
}
Also, if I wasn't using these inside a class, what would the this
in the connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(netReplyFinished(QNetworkReply*)));
be?
Thanks!
Yes, see the documentation of QNetworkRequest.
You'll want to do something like:
QNetworkRequest request(url);
request.setHeader( QNetworkRequest::ContentTypeHeader, "some/type" );
request.setRawHeader("Last-Modified", "Sun, 06 Nov 1994 08:49:37 GMT");
manager->get( header );
Also, if I wasn't using these inside a class, what would the this in the connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(netReplyFinished(QNetworkReply*))); be?
It wouldn't be anything. To connect a signal to a slot, that slot must be a member function of some object. The Qt primer on signals and slots explains this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With