Send json correctly over HTTP request
이전 댓글 표시
Hello,
I somehow do not manage to send json data to an API. The curl request is like the following
curl --request POST --url 'https://example.com/exemplary_suburl/' -d 'data={json_data:values}' --header 'appkey: abcdef'
My corresponding Matlab code, which currently does not work is the following:
import matlab.net.http.*
import matlab.net.http.field.*
header = [ContentTypeField( 'application/json' ), ...
HeaderField('appkey','exampleone')];
request = RequestMessage('POST', ...
header, jsonencode(structSample));
options = matlab.net.http.HTTPOptions();
response = request.send('https://example.com/exemplary_suburl/', options);
There is always an error as the data parameter is not in a correct format. What parameters may I change to get it working?
Thank you!
댓글 수: 3
Mario Malic
2021년 2월 4일
편집: Mario Malic
2021년 2월 4일
You call a function with no input arguments and that is probably the cause of an error.
request = RequestMessage('POST', header, jsonencode(struct));
% ^^ it's a function
Alina D
2021년 2월 4일
Mario Malic
2021년 2월 4일
Oh, I see. Well, unfortunatelly I can help with this, maybe someone else can. Meanwhile, here's a partial example example of HTTP request message.
답변 (0개)
카테고리
도움말 센터 및 File 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!