Download file using "websave" from a website that requires login

17 views (last 30 days)
I am trying to download the following file from NASA's Archive of Space Geodesy Data:
but I am having a hard time downloading the file to my computer using websave because downloading the file requires login information.
When the file download link is clicked, it first redirects to a login page, and when the correct credentials are entered, it then redirects back to the original link (which is the one above) and the file is downloaded. I was wondering whether there is a way to download the file despite the login information and redirection being required. Currently, my code returns an html file of the login page.
Here is the code I am using if it is of any help:
filename = 'RINEXFile.rnx.gz';
fileurl = 'https://cddis.nasa.gov/archive/gnss/data/daily/2021/143/21h/MAR700SWE_R_20211430000_01D_SN.rnx.gz'
websave(filename,fileurl)
  5 Comments
Abhinav Pandey
Abhinav Pandey on 1 Jun 2021
I have not done that yet. I will try asking the adminds for a REST interface.
Irem Köz
Irem Köz on 2 May 2022
I wonder whether there is any progress about this problem or not? I also have the same problem with the same website.

Sign in to comment.

Answers (1)

Abhiram
Abhiram on 17 Feb 2025
Edited: Abhiram on 17 Feb 2025
In order to to download the file, you can follow the given steps:
  • The login information must be specified using a 'POST' request to the login form.
  • The web cookies will be provided in the response message.
  • These web cookies should then be used in a 'GET' request to download the necessary file.
The code given below shows an example on how to implement 'POST' and 'GET' requests:
import matlab.net.*;
import matlab.net.http.*;
import matlab.net.http.field.*;
% POST Request
uriPost = URI('https://www.httpbin.org/post');
data = struct ('msg', 'hello world', 'date', datetime('now'));
acceptHeader = AcceptField('application/json');
contentType = ContentTypeField('application/json');
headers = [contentType, acceptHeader];
httpOpts = HTTPOptions;
r = RequestMessage ('POST', headers, data);
[resp, req, hist] = r.send(uriPost, httpOpts);
out = resp.Body.Data;
% GET Request
uriGet = URI('https://www.httpbin.org/get');
acceptHeader = AcceptField('application/json');
headers = acceptHeader;
httpOpts = HTTPOptions;
r = RequestMessage('GET',headers);
[resp, req, hist] = r.send(uriGet, httpOpts);
out = resp.Body.Data;
For additional guidance, you can refer to the MATLAB documentation for “RequestMessage”, “Cookie”, and “FormProvider” classes:

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!