Send json correctly over HTTP request

5 ビュー (過去 30 日間)
Alina D
Alina D 2021 年 2 月 4 日
コメント済み: Mario Malic 2021 年 2 月 4 日
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 件のコメント
Alina D
Alina D 2021 年 2 月 4 日
Do you refer to "struct" inside jsonencode? I am sorry, this was just a sample to hide the actual variable name.
Mario Malic
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 件)

カテゴリ

Help Center および File ExchangeCall 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