0

I am confused about http requests and how it works when requesting links.

So I know a GET requests adds parameters to urls like ?username=ABC123&password=TTT and POST just sends data to the server but thats all I get when reading tutorials out there. How would I for example send a request and download a file from a rapidgator link after authenticating? (I am a premium user).

Link to their api doc: https://support.rapidgator.net/index.php?/Knowledgebase/Article/View/89/9/do-you-have-api

The first response gives back a response object like this which gives the session id which is where I got the session id from:

{
  "response": {
    "expire_date":1351526400,
    "traffic_left":0,
    "reset_in":11695
  },
  "response_status":200,
  "response_details":null
}

This is my code:

const rp = require('request-promise');
const url = 'http://rapidgator.net/api/user/login';
const opts = {
  uri: url,
  qs: {
    username: '**censored**',
    password: '**censored**',
  },
  headers: {
    'User-Agent': 'Request-Promise'
},
  json: true
}

rp(opts)
.then(( resp ) => {
  const sessionId = resp.session_id;
  const postOpts = {
    uri: 'http://rapidgator.net/api/user/info?sid=knf3pqpg3ldm05qnol0sn16326',
    method: 'POST',
    body: {
      session_id: sessionId
    },
    json: true
  }
  rp(postOpts)
  .then(res => {
    console.log(cyan(JSON.stringify(res, null, 2)));
  })
})
.catch(( err ) => {
  throw Error(err);
});

Am I approaching this the wrong way? How do I proceed to download links from rapidgator?

Chris
  • 973
  • 1
  • 8
  • 20
  • 1
    You seem to be halfway there already. At a high level, looking at that page, they have a `Get download url` example, which I think is what you want. Basically your second request should be to that `api/file/download` endpoint, not to `api/user/info`. The response to that should then contain the actual URL to the file, which you can then make a third request to to download the file, using something like [How to download a file with Node.js](http://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries) (I assume you are running this on node) – Karl Reid May 12 '17 at 16:32
  • Thank you. I get it now, got it all workin! – Chris May 12 '17 at 20:14

0 Answers0