Hello I need please some help to implement the below "Python" code in MATLAB.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello
I need please some help to implement the below "Python" code in MATLAB.
import requests
import json
url = "http://localhost:5225/api/v1/getvalue?controller=view&item=currenttime"
r = requests.get(url)
d = json.loads(r.text)
print(d["value"])
url = "http://localhost:5225/api/v1/putvalue"
putdata = {'controller':'View','item':'time','value':d['value']}
r = requests.post(url,json = putdata)
print(r.status_code)
0 Kommentare
Antworten (1)
Sachin
am 16 Mär. 2023
I understand that you want to convert your python code into MATLAB. Referring to the following information might be of good help to you:
url = "http://localhost:5225/api/v1/getvalue?controller=view&item=currenttime";
options = weboptions('Timeout',60); % Setting request timeout to 60 seconds
r = webread(url,options);
d = jsondecode(r);
disp(d.value);
url = "http://localhost:5225/api/v1/putvalue";
putdata = struct('controller', 'View', 'item', 'time', 'value', d.value);
options = weboptions('Timeout',60); % Setting request timeout to 60 seconds
r = webwrite(url, putdata, options);
disp(r.StatusCode);
For more information about RESTful web services you can refer :
Siehe auch
Kategorien
Mehr zu Call Web Services from MATLAB Using HTTP finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!