读取 HTTP 标头
我正在尝试将我的应用程序与网络服务连接,此处,用户建议将自定义标头发送回我的应用程序。
我正在使用
void Coonnec::serviceRequestFinished(QNetworkReply *reply)
{
QByteArray bytes = reply->readAll();
if (reply->error() != QNetworkReply::NoError) {
qDebug() << "Reply error: " + reply->errorString();
}
else
{
qDebug() << "Uploaded: " + QDateTime::currentDateTime().toString();
qDebug() << reply->rawHeaderList();
}
reply->close();
bytes.clear();
reply->deleteLater();
}
php 中的这段代码,我发送这个标头,
header('XAppRequest-Status: complete');
当运行应用程序时,我可以看到我得到了这个标头,但我无法获取它的值,因为
reply->rawHeader(bytes);
什么都不返回。
我如何获取“完整”值?
I am trying to connect my application with a web service and here ,a user suggested to send custom headers back to my application.
I am using this code
void Coonnec::serviceRequestFinished(QNetworkReply *reply)
{
QByteArray bytes = reply->readAll();
if (reply->error() != QNetworkReply::NoError) {
qDebug() << "Reply error: " + reply->errorString();
}
else
{
qDebug() << "Uploaded: " + QDateTime::currentDateTime().toString();
qDebug() << reply->rawHeaderList();
}
reply->close();
bytes.clear();
reply->deleteLater();
}
from php i send this header
header('XAppRequest-Status: complete');
When running the application i can see that i get this header but i can't take the value of it cause
reply->rawHeader(bytes);
returns nothing.
How can i take the value 'complete'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议将一个插槽连接到您回复的
void QNetworkReply::metaDataChanged ()
信号。Qt 文档说
我确实在 Qt 中使用网络服务/客户端,并且我注意到某些标头信息在我预期的情况下不可用!我必须“等待”这个信号来检查标题内容。
I suggest to connect a slot to the
void QNetworkReply::metaDataChanged ()
signal of your reply.The Qt doc says
I do use web-services/client with Qt and I noticed that some header's information are not available when I expected it to be ! I had to 'wait' for this signal to check the header content.