PDA

View Full Version : Unable to download file at URL, works fine in Chromium/Firefox/cURL



blooglet
13th August 2011, 13:19
I'm trying to download a private Google Calendar using a QNetworkAccessManager. Google offers an iCal export function through URLs similar to https://www.google.com/calendar/ical/[MY E-MAIL ADDRESS]/private-[RANDOM STRING OF LETTERS AND NUMBERS]/basic.ics. This calendar can be accessed by other applications through this URL, as described in Google Calendar's documentation (http://www.google.com/support/calendar/bin/answer.py?answer=37111).

I use the following code to download a file from a given URL.



// _naMgr is a function member of type QNetworkAccessManager
connect(&_naMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(buildCalendar(QNetworkReply*)));
_naMgr.get(QNetworkRequest(_url));


void Calendar::buildCalendar(QNetworkReply* reply) {
_content = reply->readAll();

// TODO: debug
QMessageBox msg;
msg.setText(_content);
msg.exec();
}

So then I tried downloading my private calendar through the URL provided by Google. This works fine in Chromium, vanilla Firefox (i.e. no prior session data or cookies) and cURL. However, when I try to access the URL through my little program I am served with this Dutch error page (http://jsfiddle.net/blooglet/95JPZ/). (It says "Feed Processing Error".)

Is there something specific in Qt's way of handling URLs that may cause Google's server to respond differently?

ChrisW67
14th August 2011, 05:54
No, Qt does the right thing with URLs.

Since you don't show us how you construct your URL it is hard for any help to be offered.

squidge
14th August 2011, 12:03
You can use something like etherpeek or wireshark to determine the differences between your code and what Firefox/etc uses.

You have not provided sufficient code for us to offer any other help.

blooglet
16th August 2011, 14:10
I've created a new calendar on which I can reproduce the same behavior.

https://www.google.com/calendar/ical/38e7dvaj3mnlrlb2kcsuamugcs%40group.calendar.google .com/private-4c87c506a44134d2f6a0f0be1d82ee3c/basic.ics

blooglet
16th August 2011, 17:09
You have not provided sufficient code for us to offer any other help.
I've narrowed it down to this...


// --- MAIN.CPP ---
#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}



// --- MAINWINDOW.H ---

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QNetworkAccessManager>

class QNetworkReply;

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);

private:
QNetworkAccessManager _naMgr;
private slots:
void downloadedURL(QNetworkReply*);
};

#endif // MAINWINDOW_H



// --- MAINWINDOW.CPP ---

#include "mainwindow.h"

#include <QMessageBox>
#include <QNetworkReply>
#include <QNetworkRequest>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
connect(&_naMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadedURL(QNetworkReply*)));
_naMgr.get(QNetworkRequest(QUrl("https://www.google.com/calendar/ical/38e7dvaj3mnlrlb2kcsuamugcs%40group.calendar.google .com/private-4c87c506a44134d2f6a0f0be1d82ee3c/basic.ics")));
}

void MainWindow::downloadedURL(QNetworkReply* reply) {
QString content = reply->readAll();

QMessageBox msg;
msg.setText(content);
msg.exec();
}

squidge
16th August 2011, 18:33
So your passing an encoded string to a constructor (QUrl) which expects a non-encoded string? So whats probably happening is that QUrl is then confusing the web server by encoding your encodings.

Try changing your URL to human readable format instead. Eg. replace things like %40 with the actual character (which I think is @)

javed_alam786
25th August 2011, 15:24
i see your are using https you might be getting SSL error probably SSL Handshake Error.

Try using


reply->ignoreSslErrors();


Note that calling this function without restraint may pose a security risk for your application. Use it with care.

Read document here (http://doc.qt.nokia.com/latest/qnetworkreply.html#ignoreSslErrors)

blooglet
13th September 2011, 14:39
So your passing an encoded string to a constructor (QUrl) which expects a non-encoded string? So whats probably happening is that QUrl is then confusing the web server by encoding your encodings.

Try changing your URL to human readable format instead. Eg. replace things like %40 with the actual character (which I think is @)
You're right, it works if I apply QUrl::fromEncoded to the encoded string first. Thanks!