Hello I need please some help to implement the below "Python" code in MATLAB.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Sachin
2023-3-16
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 :
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!