Matlab RESTful PUT Command - net.http - nesting body values

纵然是瞬间 提交于 2019-12-13 04:28:53

问题


I am using Matlab's matlab.net.http library to launch get, put and post commands to a website. I can successfully launch get and post commands.

For example: MyBody = matlab.net.http.MessageBody(struct('Id',YYYYYY,'WindfarmId',XXX,'Month','YYYY-MM-DD')); Request = matlab.net.http.RequestMessage; Request.Method = 'POST'; Request.Header = matlab.net.http.HeaderField('Content-Type','application/json','Authorization',['Basic ' matlab.net.base64encode([Username ':' Password])]); Request.Body = MyBody; uri = matlab.net.URI(ENTERURLHERE); Response = Request.send(uri,MyHTTPOptions); This works well. However using a PUT command I have to enter the equiavlent of this body (written in curl syntax):

-d '{ "InputValues": [ {"MetricLevelAId": 1, "MetricLevelBId": 1, "InputMetricId": 7, "Value": 56 } ] }'

I tried this:

data_InputValues = struct ('MetricLevelAId',1,'MetricLevelBId',1,'InputMetricId',7,'Value',56);
MyBody = matlab.net.http.MessageBody(struct('InputValues',dataInputValues));

However I keep receiving the following 'Bad Request' response from the server: "Input values required"

I think this is linked to the way Matlab interprets the body part of the request and passes it to the server, i.e. it cannot pass the nested struct correctly. Anyone got any ideas how to solve this?

N.B. potentially linked to Translating curl into Matlab/Webwrite (it is dealing with a nested value)

来源:https://stackoverflow.com/questions/50416587/matlab-restful-put-command-net-http-nesting-body-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!