我已经使用Matlab的webwrite()
调用REST API,并提供了requset参数。但是,我现在需要在必须指定请求正文的位置进行调用。有没有办法做到这一点?
REST API由Java Spring控制器定义,例如:
@PostMapping(value = "post")
public ResponseEntity<?> setMySTuff(
@RequestParam(name = "myId") int myId,
@RequestBody Collection<MyCustomObject> myObjList) {
webwrite的THe数据参数似乎旨在成为一组键/值请求参数对,而不是设置请求正文的一种方法。
发布于 2018-02-12 20:48:40
如果我没记错的话,@RequestParam
用于将值映射为查询参数,而@RequestBody
定义响应的内容。如果我的假设是有效的,Matlab的等价物应该是:
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);
https://stackoverflow.com/questions/48752432
复制相似问题