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

17 ビュー (過去 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 Center および File ExchangeCall 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