Delphi TRestRequest array parameter

前端 未结 1 550
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 06:31

This might be a simple one.

I\'m accessing a RESTFul service with Delphi XE6 using RestClient components: TRestClient, TRestRequest, TRestResponse and THTTPBasicAuth

相关标签:
1条回答
  • 2020-12-20 07:07

    Done! It looks like I was doing it the wrong (or complicated) way. The service was expecting a JSON object and I was building it property by property. There is an easier way:

    var aParam: TRESTRequestParameter;
    begin
      RestReq.Method := rmPOST; {or rmGET, ...}
      aParam := RestReq.Params.AddItem(); //don't care about setting a name for it
      aParam.Value := TJSONObject.ParseJSONValue('{"param1":"value1","param2":"value2","param3":["v1","v2","v3"]}');
      aParam.ContentType := ctAPPLICATION_JSON;
      //set proxy params, resource, etc.
      RestClient.Execute();
    end;
    

    And that will do! Thanks all for your comments.

    0 讨论(0)
提交回复
热议问题