Hello I need please some help to implement the below "Python" code in MATLAB.

1 vue (au cours des 30 derniers jours)
ルオン
ルオン le 16 Mar 2023
Commenté : ルオン le 16 Mar 2023
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)

Réponses (1)

Sachin
Sachin le 16 Mar 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 :

Catégories

En savoir plus sur Call Web Services from MATLAB Using HTTP dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by