Ich versuche, eine Verbindung zu einer PHP-Seite herzustellen.QT QNetworkReply und PHP
ist egal was ich mache, aber QNetworkReply ist immer leer.
das ist mein Code, hoffe jemand hat eine Idee.
QUrl url("http://mysite.it/interface.php");
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QUrlQuery params;
//list of params
url.setQuery(params);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
manager->post(request,params.toString(QUrl::FullyEncoded).toUtf8());
connect(this, SIGNAL(confirm_signal()), reciver, SLOT(recive_confirm()));
dies ist der Schlitz für die Antwort
void database::replyFinished(QNetworkReply *reply){
if(reply->error())
{
qDebug() << "ERROR!";
qDebug() << reply->errorString();
}
else {
qDebug()<< reply->readAll().toInt();
qDebug()<< reply->readAll().trimmed();
QByteArray array = reply->readAll();
QString str(array);
reply->deleteLater();
qDebug() << "array" <<array;
qDebug() <<"string" <<str;
QString str2 = QString::fromUtf8(array.data(), array.size());
qDebug() <<str2;
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << QVariant(statusCode).toString();
emit confirm_signal();
}
}
alle qDebug() gibt "" als Antwort, mit Ausnahme der Statuscode, ist "200".
<?php
json_encode("Ok");
?>
der pHP-Code am Ende ist der Inhalt von 'interface.php'-Datei? – Mike
Ja, um ehrlich zu sein, hat Google mir keine Ahnung gegeben, wie man die Antwort zurückgibt..so getestet mit echo und json_encode – user3787626