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

조회 수: 4 (최근 30일)
Abhinav Pandey
Abhinav Pandey 2021년 6월 1일
편집: Abhiram 2025년 2월 17일
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
Abhinav Pandey
Abhinav Pandey 2021년 6월 1일
I have not done that yet. I will try asking the adminds for a REST interface.
Irem Köz
Irem Köz 2022년 5월 2일
I wonder whether there is any progress about this problem or not? I also have the same problem with the same website.

댓글을 달려면 로그인하십시오.

답변 (1개)

Abhiram
Abhiram 2025년 2월 17일
편집: Abhiram 2025년 2월 17일
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:

카테고리

Help CenterFile Exchange에서 Call Web Services from MATLAB Using HTTP에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by