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
Thomas Anvidalfarei 2024년 1월 10일
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 커뮤니티

카테고리

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