Receive data via HTTP

3 次查看(过去 30 天)
Enrico Anderlini
Enrico Anderlini 2019-8-30
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 中查找有关 Call Python from MATLAB 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by