Receive data via HTTP

조회 수: 9 (최근 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 CenterFile Exchange에서 Python Client Programming에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by