0

I've used Matlab's webwrite() to make calls to a REST API, providing the requset params. However, I need to now make a call where the Request Body must be specified. Is there a way to do this?

The REST API is defined by a Java Spring controller, e.g.:

@PostMapping(value = "post") public ResponseEntity<?> setMySTuff( @RequestParam(name = "myId") int myId, @RequestBody Collection<MyCustomObject> myObjList) { 

THe data paramemter for webwrite seems intended for being a set of key/value request param pairs, and not a means of setting the request body.

1 Answer 1

1

If I remember correctly, @RequestParam is used for mapping values as query parameters, while @RequestBody defines the content of the response. If my assumptions are valid, the Matlab equivalent should be:

url = ['http://mywebsite.net/service/?myId=' num2str(5778)]; body = struct('Item1','Hello','Item2','World'); opts = weboptions('MediaType','application/json','RequestMethod','post'); response = webwrite(url,body,opts); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.