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

1 view (last 30 days)
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 Comments
Thomas Anvidalfarei
Thomas Anvidalfarei on 10 Jan 2024
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 on 14 Jan 2024
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?

Sign in to comment.

Accepted Answer

Austin Jacobs
Austin Jacobs on 23 May 2022
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');

More Answers (0)

Communities

More Answers in the  ThingSpeak Community

Tags

Community Treasure Hunt

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

Start Hunting!