예제 #1
0
void RequestModel::update()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
    if (!reply)
        return;

    int offset;
    for (offset = m_requests.count() - 1; offset >= 0; --offset) {
        if (m_requests[offset].reply == reply)
            break;
    }
    if (offset < 0)
        return;

    // Save reply headers
    foreach (const QByteArray &header, reply->rawHeaderList() ) {
        QPair<QByteArray, QByteArray> pair(header, reply->rawHeader(header));
        m_requests[offset].replyHeaders.append(pair);
    }

    // Save reply info to be displayed
    int status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
    QString reason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
    m_requests[offset].response = QString(QLatin1String("%1 %2")).arg(status).arg(reason);
    m_requests[offset].length = reply->header(QNetworkRequest::ContentLengthHeader).toInt();
    m_requests[offset].contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();

    if (status == 302) {
        QUrl target = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl();
        m_requests[offset].info = tr("Redirect: %1").arg(target.toString());
    }
}
QList<QByteArray> QNetworkReplyProto::rawHeaderList() const
{
  QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
  if (item)
    return item->rawHeaderList();
  return QList<QByteArray>();
}
예제 #3
0
int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

    QNetworkAccessManager manager;

    if (argc != 2) {
        std::cout << "usage: " << argv[0] << " <url>" << std::endl;
        return 0;
    }

    QUrl url(app.arguments().value(1));
    QNetworkRequest request(url);

    QNetworkReply *reply = manager.get(request);
    app.connect(reply, SIGNAL(finished()), SLOT(quit()));
    app.exec();

    QFile outfile("request.header");
    if (outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
        QTextStream stream(&outfile);
        QList<QByteArray> list = reply->rawHeaderList();
        foreach (QByteArray name, list) {
            stream << name << ": " << reply->rawHeader(name) << endl;
        }
예제 #4
0
void YandexNarodUploadJob::uploadReply()
{
	m_timer.stop();
	debug() << "uploadReply";
	QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
	Q_ASSERT(reply);
	if (!processReply(reply))
		return;

	QByteArray data = reply->readAll();
	QVariantMap map = Json::parse(data).toMap();

	debug() << "upload" << data << map;
	debug() << reply->rawHeaderList();
	debug() << "upload" << reply->rawHeader("Set-Cookie");

	someStrangeSlot();
}