Receive data via HTTP

7 Ansichten (letzte 30 Tage)
Enrico Anderlini
Enrico Anderlini am 30 Aug. 2019
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!

Antworten (1)

Enrico Anderlini
Enrico Anderlini am 6 Sep. 2019

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by