Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need help with get request and redirections

Need help with get request and redirections

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 283 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hjiul
    wrote on last edited by
    #1

    Hello everyone.
    I am very new to QT or coding in general so be gentle :)

    I am looking at downloading some csv data from a google spreadsheet.

    I have a script with a get function that retrun the csv data.
    It works correctly on my navigator.

    Now, i have tried to download datas with the following code :

    QNetworkAccessManager man;
        QNetworkRequest req(QUrl("https://script.google.com/macros/s/AKfycbySdq6clPuvG06h1bLgy1Ag4eOeutDvT0084efJpCf9Niqw-Pc/exec"));
        QNetworkReply*reply=man.get(req);
        QObject::connect(reply, &QNetworkReply::finished,[&](){
    
            QByteArray read = reply->readAll();
            //QFile req("test.csv");
            QFile out("csvdata.csv");
            out.open(QIODevice::WriteOnly|QIODevice::Text);
            out.write(read);
            out.close();
            reply->close();
            reply->deleteLater();
            a.quit();
    

    but the result is always a html error of some kind :
    <HTML>
    <HEAD>
    <TITLE>Moved Temporarily</TITLE>
    </HEAD>
    etc...

    (the error varies but always is the same idea : the link has moved somewhere else)

    So do i have a way to "track" the link or is there something i have to do to prevent that to happend ?
    I thought it would be simple... basic script that return text data, basic get request and basic file writting...
    ...
    been on that for the last 6hours...

    Knowing that the code works great if i point to a text file link somewhere.
    So i guess the fault is with google and url processing

    Im tired, please. Help me :)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      A simple approach is to add

      req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
      

      But this will not allow "https" to "http".

      1 Reply Last reply
      1
      • H Offline
        H Offline
        hjiul
        wrote on last edited by
        #3

        @Bonnie said in Need help with get request and redirections:

        req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);

        Wouhouuuu, you save my week i guess :)
        Thank you so much, that worked like a charm.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved