从应用程序连接到 php 脚本并检索数据?
connect from an app to a php-script and retrieve the data?
我正在为 Qt/QML 中的 Android 编写一个需要与 MySQL 数据库同步的应用程序。
我将使用 php 脚本在服务器和移动设备之间进行通信。
但我不明白的是如何连接到 php-web 服务并从中检索数据。
如何从应用程序连接到 php-脚本,并从 php-脚本查询到 sql 服务器的查询中检索数据?
我不需要完整的解释,只需要一点指导。我不是要被喂食。
您应该如何与脚本交互?
您需要通过 http 发送某种字符串吗?甚至可以通过 http 从服务器发送字符串或向服务器发送字符串吗?如果是这样,如何?你在 URL 或类似的东西中输入数据吗?如果是这样,php 脚本是否应该接收请求并且它可以解析 url?
只要简单描述一下这种交互的工作原理,我们将不胜感激
void Downloader::doDownload()
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://bogotobogo.com")));
}
void Downloader::replyFinished (QNetworkReply *reply)
{
if(reply->error()) { qDebug() << "ERROR!";
qDebug() << reply->errorString();
}
else
{
qDebug() << reply->header(QNetworkRequest::ContentTypeHeader).toString();
qDebug() << reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toString();
qDebug() << reply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
QFile *file = new QFile("C:/Qt/Dummy/downloaded.txt");
if(file->open(QFile::Append))
{
file->write(reply->readAll());
file->flush();
file->close();
}
delete file;
}
reply->deleteLater();
}
我正在为 Qt/QML 中的 Android 编写一个需要与 MySQL 数据库同步的应用程序。
我将使用 php 脚本在服务器和移动设备之间进行通信。
但我不明白的是如何连接到 php-web 服务并从中检索数据。
如何从应用程序连接到 php-脚本,并从 php-脚本查询到 sql 服务器的查询中检索数据?
我不需要完整的解释,只需要一点指导。我不是要被喂食。
您应该如何与脚本交互?
您需要通过 http 发送某种字符串吗?甚至可以通过 http 从服务器发送字符串或向服务器发送字符串吗?如果是这样,如何?你在 URL 或类似的东西中输入数据吗?如果是这样,php 脚本是否应该接收请求并且它可以解析 url?
只要简单描述一下这种交互的工作原理,我们将不胜感激
void Downloader::doDownload()
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://bogotobogo.com")));
}
void Downloader::replyFinished (QNetworkReply *reply)
{
if(reply->error()) { qDebug() << "ERROR!";
qDebug() << reply->errorString();
}
else
{
qDebug() << reply->header(QNetworkRequest::ContentTypeHeader).toString();
qDebug() << reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toString();
qDebug() << reply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
QFile *file = new QFile("C:/Qt/Dummy/downloaded.txt");
if(file->open(QFile::Append))
{
file->write(reply->readAll());
file->flush();
file->close();
}
delete file;
}
reply->deleteLater();
}