MATLAB http post and json request

111 Ansichten (letzte 30 Tage)
mohammad ibrahim
mohammad ibrahim am 8 Jan. 2020
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

Akzeptierte Antwort

Sylvain Lacaze
Sylvain Lacaze am 8 Jan. 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Call Web Services from MATLAB Using HTTP finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by