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. [SOLVED]Can download via web browser but got forbidden error if trying with my Qt code.
Forum Update on Monday, May 27th 2025

[SOLVED]Can download via web browser but got forbidden error if trying with my Qt code.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.5k 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.
  • S Offline
    S Offline
    SetBetterPass
    wrote on 3 Mar 2013, 14:40 last edited by
    #1

    I am trying to make downloader and one of things that it should download are videos from youtube. I found out how to get exact download link to download YT video, it looks like this :
    http://r3---sn-bunjx-cune.c.youtube.com/videoplayback?sparams=algorithm,burst,cp,factor,id,ip,ipbits,itag,source,upn,expire&source=youtube&mv=m&ipbits=8&signature=9C15646EB192EAEA3ED858C59FE1855948CC22BD.03E702E0C29389D07014F9236CE3A94ADE266984&factor=1.25&key=yt1&ip=49.150.252.23&expire=1362343471&algorithm=throttle-factor&upn=N7N9OcfAVXs&burst=40&newshard=yes&fexp=900225,906335,911410,904448,914036,916611,901461,920704,912806,902000,922403,922405,929901,913605,925006,906938,931202,908529,920201,930101,906834,926403,913570,901451&sver=3&cp=U0hVR1NPUV9MS0NONV9LSVVFOkJxVHQxanR3dFhY&mt=1362320414&itag=34&id=e1b0652454a2c279&ms=au

    I tried it in web browser and it asked me if want play in vlc or save, ok I saved it, got video downloaded, everything seems good. But in my code I send get request and reply from server is: Error downloading (url) - server replied: Forbidden. I am not sure if problem is in my code only if I have to make custom request but I have no idea what to put there...

    my code:
    @
    void MainWindow::downloadRequested(){
    for(int b=0;b<urls4Download.count();b++){
    if(!folder.endsWith("/"))folder.append("/");
    QString st = FileList.at(fileIndex[b]);
    st.replace(QRegExp("/"),QString("_"));
    file=new QFile(folder+st);
    file->open(QIODevice::WriteOnly);
    reply=nam.get(QNetworkRequest(QUrl(urls4Download.at(b)))); //actually only one url in list, the one from above
    QEventLoop loop;
    connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    connect(reply,SIGNAL(finished()),this,SLOT(saveFile()));
    connect(reply,SIGNAL(readyRead()),this,SLOT(readyReadFile()));
    loop.exec();
    }
    }
    void MainWindow::saveFile(){
    if(reply->error())QMessageBox::warning(0,"warning",reply->errorString());
    file->write(reply->readAll());
    file->flush();
    file->close();
    reply->deleteLater();
    }
    void MainWindow::readyReadFile(){
    downloadedBytes+=reply->size();
    float prog=(downloadedBytes/float(bytesToDownload))*100;
    file->write(reply->readAll());
    int progress=int(prog);
    ui->progressBar->setValue(progress);();

    }
    @

    Thanks anyone who can help me.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_ReaQtor
      wrote on 3 Mar 2013, 18:42 last edited by
      #2

      Were you able to get/output any errors?

      Anyways, some websites doesn't respond unless you set a "User Agent". I once encountered google ignoring simple search. But I was able to solve it by adding something like this:

      @QNetworkRequest request;
      request.setRawHeader("User-Agent", "MyBrowser");
      request.setUrl(/url here/);
      reply=nam.get(request);@

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mmallad
        wrote on 3 Mar 2013, 20:32 last edited by
        #3

        Ya you must set user agent to avoid problems :)

        Dpak Malla

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SetBetterPass
          wrote on 4 Mar 2013, 15:14 last edited by
          #4

          I found out my problem was with , chars parts in link, they were translated into "," as I posted it here and in browser too, after longer time I found there was my problem. But thanks anyway this user-agent header may help me later :)

          1 Reply Last reply
          0

          1/4

          3 Mar 2013, 14:40

          • Login

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