Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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)

Risposte (1)

Sachin
Sachin il 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 :

Community Treasure Hunt

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

Start Hunting!

Translated by