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

1 回表示 (過去 30 日間)
ルオン
ルオン 2023 年 3 月 16 日
コメント済み: ルオン 2023 年 3 月 16 日
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)

回答 (1 件)

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

カテゴリ

Help Center および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by