star lin
star lin

Reputation: 21

MATLAB urlread - How to POST data in JSON format?

As I know ,the urlread function can post to the URL. I did it with the string.

urlread(url, 'Post', {'userId', userid, 'Password', Password}

but There are some JSON value like that:

"country": ["US","JP"],
"student": false,

I tried this code but it failed.

urlread(url,'Post',{'userId', userid ,'Password' ,Password ,'country' ,'{'US' ,'JP'}' ,'student' ,false}

How can I POST data from Matlab to a RESTful server in JSON format?

Upvotes: 2

Views: 1223

Answers (1)

Cameron Lowell Palmer
Cameron Lowell Palmer

Reputation: 22245

Matlab webwrite

You'll find that urlread has been replaced by webread and webwrite and that it automatically handles JSON serialization. So you can just create a Matlab struct and hand that to webwrite.

url = 'http://example.com'
data = struct('userId', userId ,'Password' , password, 'country', {'US', 'JP'}, 'student', false)
webwrite(url, data);

Upvotes: 1

Related Questions