Receive data via HTTP

8 ビュー (過去 30 日間)
Enrico Anderlini
Enrico Anderlini 2019 年 8 月 30 日
回答済み: Enrico Anderlini 2019 年 9 月 6 日
I need to access CSV-formatted data on a server, which requires a token for me to be granted access. My colleagues usually access this service with Python. However, as my code is all in MATLAB, I would prefer the data in MATLAB so that I can use my existing functions, which I have already verified.
In Python, we use the requests package as follows:
timeseries_url = 'https:// .... /csv'
payload = { 'variable': ['var1','var2'], 'platform_serial' : 'name_of_platform' , 'from' : 'start_time' , 'to' : 'end_time' }
header = {'Authorization': 'Bearer ' + 'authorisation_token'}
# Get the response:
response = requests.get(timeseries_url, headers=header, params=payload)
df = pandas.read_csv(io.StringIO(response.text))
I have been reading the MATLAB documentation for the HTTP interface. However, I have noticed there is no equivalent get command, but only the send.
I think the token should be entered in the matlab.net.http.HTTPOptions object as 'Credentials'. Similarly, the header could be the 'Header' matlab.net.http.RequestMessage. Besides, I think the payload could be obtained through 'getFields'. Are these assumptions correct?
How can I best achieve this task in MATLAB? Additionally, how can I change the data from CSV to matrices/cells for later use? I do not think using csvread or readmatrix here is appropriate.
My alternative is the MATLAB engine for Python, but I would prefer a neat, all-MATLAB solution.
Many thanks in advance for your help!

回答 (1 件)

Enrico Anderlini
Enrico Anderlini 2019 年 9 月 6 日

カテゴリ

Help Center および File ExchangePython Client Programming についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by