I'm trying to post to a restful service with Matlab. I've tried using webread, webwrite, and urlread and I cannot figure out how to set the body of the message.
My body is json and looks like this:
{"Item1": "string1", "Item2": "string2"}
I found out what I was doing wrong. I was constructing my body as a string literal and not as a matlab struct. Correct way:
api = 'http://myurl.net'; url = [api, '/Login']; [un, pw] = GetAuthentication; input = struct('Username',un,'Password',pw); opts = weboptions('MediaType','application/json'); userInfo = webwrite(url, input, opts);
webwriteinstead ofwebread?