MATLAB http post and json request

105 ビュー (過去 30 日間)
mohammad ibrahim
mohammad ibrahim 2020 年 1 月 8 日
コメント済み: mohammad ibrahim 2020 年 1 月 8 日
Hello
I need please some help to implement the below "Python" code in MATLAB.
I want to be able to perform a request to identify if a key exists and if it is valid through connecting to a certain website
%% Python code ================================
import requests
import json
data = requests.post(
"https://api.somewebsite/accounts/CC/licenses/actions/validate-key",
headers={
"Content-Type": "application/vnd.api+json",
"Accept": "application/vnd.api+json"
},
data=json.dumps({
"meta": {
"key": "xxxxxxxxxxxxxxxxxxx"
}
})
).json()
if data["meta"]["valid"]:
# Do something
else:
# Do something else
%% ================================
many thanks
Mohammad

採用された回答

Sylvain Lacaze
Sylvain Lacaze 2020 年 1 月 8 日
Hi Mohammad,
I would start with something like this:
import matlab.net.http.*
import matlab.net.http.field.*
request = RequestMessage( 'POST', ...
[ContentTypeField( 'application/vnd.api+json' ), AcceptField('application/vnd.api+json')], ...
'{"meta": {"key": "xxxxxx"}}' );
response = request.send( 'https://api.somewebsite/accounts/CC/licenses/actions/validate-key' );
And use this doc page to work out your logic once you have the response:
For reference, the wider documentation is here:
HTH,
Sylvain
  1 件のコメント
mohammad ibrahim
mohammad ibrahim 2020 年 1 月 8 日
many thanks Sylvain

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by