In MATLAB Analysis, how do I set HTTPOptions to mirror webwrite options?

1 次查看(过去 30 天)
I'm trying to recreate an HTTP POST in MATLAB analysis which is workign in Postman, so that I can use the data from the Huawei SolarFusion Northbound API in my project.
The login endpoint I'm using requires consumers to inspect the headers in the response. It returns 17 headers, one of which is an xsrf-token with a correspoding value I need to extract.
I tried using MATLAB webwrite function, the call is successful when I set weboptions as:
options = weboptions('MediaType','application/json','RequestMethod','post','CertificateFilename', '');
...
S = webwrite(url, data, options);
display (S,'look at this');
, but I couldn't find headers in the return object, S, the display output is:
struct with fields:
data: []
success: 1
failCode: 0
params: [1×1 struct]
message: []
So I am attempting to use native HTTP send(request,uri,httpOptions) but am getting:
ResponseMessage with properties:
StatusLine: 'HTTP/1.1 500 Internal Server Error'
StatusCode: InternalServerError
Header: [1×17 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0
Great news that the headers are there, but I cannot make the call succeed.
I am using HTTPOptions and this is tricky to figure out the equivalent settings to webwrite options. I believe HTTPOptions of ('Authenticate',false) is equivalent to weboptions of ('CertificateFilename', '') and this is a possible cause of the error.
uri = url;
httpOptions = matlab.net.http.HTTPOptions('Authenticate',false);
[response,completedrequest,history] = send(request,uri,httpOptions);
display(response, ' Response ');
  2 个评论
Thomas Anvidalfarei
Hello,
I am interested in analysing my PV data using Matlab. Since I am a hobby programmer and am not familiar with API interfaces, I download the Excel files from the fusion solar portal every month and import them.
Since I assume that you have created the code for the interface, I would like to ask if you would make it available to us. Of course with anonymised login data.
Thanks
Thomas
Austin Jacobs
Austin Jacobs 2024-1-14
Hi Thomas, I'm also a hobbyist so of limited help here. I never got a working connection to Huawei SolarFusion Northbound API in my project. Having said that, my focus changed so I appeared to have answered my specific challenge about headers in the thread here already. I am now looking to read and control my inverter in near real time so plan to use a totally different architecture using a local machine running Home Assistant. Sorry not to be of more help. If there's a specific challenge you have, maybe I can go look at it? Did you request API access from Huawei support?

请先登录,再进行评论。

采纳的回答

Austin Jacobs
Austin Jacobs 2022-5-23
Withdrawing qustion after resolving by replacing HeaderField:
%header = matlab.net.http.HeaderField('Media-Type','application/json');
header = matlab.net.http.HeaderField('Content-Type', 'application/x-www-form-urlencoded');

更多回答(0 个)

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 Call Web Services from MATLAB Using HTTP 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by