A solution to the question can be found here: https://stackoverflow.com/questions/57806162/receive-data-via-http-in-matlab/57822547#57822547
Receive data via HTTP
4 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!