向Piwik提交Delphi POST请求时的问题

时间:2013-10-17 11:53:03

标签: delphi post indy matomo

我尝试向Piwik提交Delphi POST请求,如下所示:http://piwik.org/docs/tracking-api/reference/#toc-advanced-bulk-tracking-requests

我的Delphi实现如下所示:

  FPiwikRequest := '';
  FPiwikRequest := FPiwikRequest + Format('?cvar=PAGE_%s&', ['something']);
  FPiwikRequest := FPiwikRequest + Format('action_name=6new_%s&', ['ActionPage']);
  FPiwikRequest := FPiwikRequest + Format('idsite=%d&', [3]);
  FPiwikRequest := FPiwikRequest + Format('rec=%d&', [1]);
  FPiwikRequest := FPiwikRequest + Format('url=%s&', ['http://localhost/analytics/index45.html']);
  FPiwikRequest := FPiwikRequest + Format('urlref=%s&', ['http://localhost/analytics/index13.html']);
  FPiwikRequest := FPiwikRequest + Format('_id=%s&', ['231e3849e534a3c6']);
  FPiwikRequest := FPiwikRequest + Format('rand=%d', [Random(1000)]);
  json := SO;
  json.O['requests'] := SA([]);
  json.A['requests'].S[0] := FPiwikRequest;
  json.A['requests'].S[1] := FPiwikRequest_2;
  json.S['token_auth'] := 'ffff9fb80b9558e4529fe96902dffff';
  FPiwikRequest := json.AsString;
  HTTPClient.POST(PIWIK_HOME + FPiwikRequest, response); //HTTPClient => idHTTP class

提交请求后,Piwik脚本仅处理上次请求json.A ['requests']。来自提交的批量请求的S [1]。

* 当我从Python提交相同的批量请求时,Piwik会处理来自提交的批量请求的请求。

您对此类Delphi POSTing行为有什么想法吗?

1 个答案:

答案 0 :(得分:1)

对不起,这篇文章。答案很简单:),其中一种方法如下所示。

因此,您应该将Params添加到方法POST

LRequestParams := TStringStream.Create();
try
  LRequestParams.WriteString(FPiwikRequest);  
  HTTPClient.POST(PIWIK_HOME, LRequestParams, response);
finally
  LRequestParams.Free;   
end;