POST请求无效

时间:2019-01-30 22:05:39

标签: matlab rest request http-post

我有一个批处理Post请求,可以通过MATLAB提交给API。我不知道如何以有效方式构造请求的正文。 MATLAB和API文档都没有为我提供足够详细的帮助。

请求看起来像这样:

{
  "requests": [
{
  "id": "sample string 1",
  "seriesType": "sample string 2",
  "startDate": 1548882319358,
  "endDate": 1548882319358,
  "currency": "sample string 5",
  "sdkVersion": "sample string 6"
},
{
  "id": "sample string 1",
  "seriesType": "sample string 2",
  "startDate": 1548882319358,
  "endDate": 1548882319358,
  "currency": "sample string 5",
  "sdkVersion": "sample string 6"
},
{
  "id": "sample string 1",
  "seriesType": "sample string 2",
  "startDate": 1548882319358,
  "endDate": 1548882319358,
  "currency": "sample string 5",
  "sdkVersion": "sample string 6"
}
],
  "sdkVersion": "sample string 1"
 } 

我当前的代码如下:

M = length(entities);
K = length(series);
maxAttempt = 20;

method = matlab.net.http.RequestMethod.POST;
uri = strcat([api.baseURI 'Entities/SeriesBatch']);
body = matlab.net.http.MessageBody;
body.Data.requests = cell(M*K,1);
n = 0;
for ii = 1:M
    for jj = 1:K
        n = n + 1;
        body.Data.requests{n} = struct;
        body.Data.requests{n}.id = entities{ii};
        body.Data.requests{n}.seriesType = series{jj};
        body.Data.requests{n}.startDate = startDate;
        body.Data.requests{n}.endDate = endDate;

    end
end

N = 0;
response.Completed = true;

while and(response.Completed, N < maxAttempt)
    clear response
    header = myAPIHeader(api);
    request = matlab.net.http.RequestMessage(method,header,body);
    response = send(request,uri);
    N = N + 1;
end

但是我收到无效的请求消息。这是构造此大批量请求(M = 1133,K = 5)时最好的客人。

0 个答案:

没有答案