webwrite to query web API data issue

I used webwrite to query web API data, when I use below code, it works well.
url = 'https://open.lixinger.com/api/a/index';
options = weboptions('RequestMethod','post','ContentType','json');
token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'; %% my Web API token
stockcode = ["000016", "399986"]; %% this is to define stockcode string array!
request_body = struct("token", token, "stockCodes", stockcode);
response = webwrite(url, request_body, options);
BUT when i try to use only one stockcode, query works but no data in it. no errors.
url = 'https://open.lixinger.com/api/a/index';
options = weboptions('RequestMethod','post','ContentType','json');
token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'; %% my Web API token
stockcode = "000016"; %% I only use one stockcode here!!! it not work!! seems this definition is not exactly same as above.
request_body = struct("token", token, "stockCodes", stockcode);
response = webwrite(url, request_body, options); %% there is respose but no data in it.
https://open.lixinger.com/api/a/index Web API request parameter "stockCodes" is Array type.
anyone can help on this?
appreciate!!!

1 Comment

I can't replicate the API interaction since the API no longer exists, but it looks like you were very close. "webwrite" is the way to go: https://www.mathworks.com/help/matlab/ref/webwrite.html

Sign in to comment.

Answers (0)

Asked:

on 6 Mar 2021

Commented:

on 4 Oct 2023

Community Treasure Hunt

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

Start Hunting!