Results 1 to 8 of 8

Thread: Unable to download file at URL, works fine in Chromium/Firefox/cURL

  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Unable to download file at URL, works fine in Chromium/Firefox/cURL

    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.

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

    Qt Code:
    1. // _naMgr is a function member of type QNetworkAccessManager
    2. connect(&_naMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(buildCalendar(QNetworkReply*)));
    3. _naMgr.get(QNetworkRequest(_url));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Calendar::buildCalendar(QNetworkReply* reply) {
    2. _content = reply->readAll();
    3.  
    4. // TODO: debug
    5. msg.setText(_content);
    6. msg.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    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. (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?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Unable to download file at URL, works fine in Chromium/Firefox/cURL

    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.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unable to download file at URL, works fine in Chromium/Firefox/cURL

    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.

  4. #4
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unable to download file at URL, works fine in Chromium/Firefox/cURL

    I've created a new calendar on which I can reproduce the same behavior.

    https://www.google.com/calendar/ical...ee3c/basic.ics

  5. #5
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unable to download file at URL, works fine in Chromium/Firefox/cURL

    Quote Originally Posted by squidge View Post
    You have not provided sufficient code for us to offer any other help.
    I've narrowed it down to this...

    Qt Code:
    1. // --- MAIN.CPP ---
    2. #include <QtGui/QApplication>
    3. #include "mainwindow.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. MainWindow w;
    9. w.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // --- MAINWINDOW.H ---
    2.  
    3. #ifndef MAINWINDOW_H
    4. #define MAINWINDOW_H
    5.  
    6. #include <QtGui/QMainWindow>
    7. #include <QNetworkAccessManager>
    8.  
    9. class QNetworkReply;
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. MainWindow(QWidget *parent = 0);
    17.  
    18. private:
    19. QNetworkAccessManager _naMgr;
    20. private slots:
    21. void downloadedURL(QNetworkReply*);
    22. };
    23.  
    24. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // --- MAINWINDOW.CPP ---
    2.  
    3. #include "mainwindow.h"
    4.  
    5. #include <QMessageBox>
    6. #include <QNetworkReply>
    7. #include <QNetworkRequest>
    8.  
    9. MainWindow::MainWindow(QWidget *parent)
    10. : QMainWindow(parent)
    11. {
    12. connect(&_naMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadedURL(QNetworkReply*)));
    13. _naMgr.get(QNetworkRequest(QUrl("https://www.google.com/calendar/ical/38e7dvaj3mnlrlb2kcsuamugcs%40group.calendar.google.com/private-4c87c506a44134d2f6a0f0be1d82ee3c/basic.ics")));
    14. }
    15.  
    16. void MainWindow::downloadedURL(QNetworkReply* reply) {
    17. QString content = reply->readAll();
    18.  
    19. msg.setText(content);
    20. msg.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unable to download file at URL, works fine in Chromium/Firefox/cURL

    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 @)

  7. The following user says thank you to squidge for this useful post:

    blooglet (13th September 2011)

  8. #7
    Join Date
    Jan 2011
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unable to download file at URL, works fine in Chromium/Firefox/cURL

    i see your are using https you might be getting SSL error probably SSL Handshake Error.

    Try using
    Qt Code:
    1. reply->ignoreSslErrors();
    To copy to clipboard, switch view to plain text mode 

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

    Read document here

  9. #8
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unable to download file at URL, works fine in Chromium/Firefox/cURL

    Quote Originally Posted by squidge View Post
    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!

Similar Threads

  1. Replies: 15
    Last Post: 8th June 2013, 06:15
  2. Replies: 1
    Last Post: 31st December 2010, 16:35
  3. Replies: 3
    Last Post: 11th December 2009, 17:13
  4. Replies: 1
    Last Post: 30th March 2009, 22:25
  5. update() works fine sometime but not everytime..!!
    By salmanmanekia in forum Qt Programming
    Replies: 19
    Last Post: 22nd August 2008, 09:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.