Joe Sansalone 6 Posted November 7, 2023 (edited) I'm trying to add the same parameter name multiple times with different values (using POST). It seems like separating values via semi-colon ; and using poFlatArray only works for a GET request. FRestRequest.Params.AddItem('MediaUrl', values , TRestRequestParameterKind.pkGETorPOST, [poFlatArray]); Simply doing multiple AddItem erases previous entry if the parameter name is the same. So, How do I add the same parameter multiple times? Edited November 7, 2023 by Joe Sansalone Share this post Link to post
Fr0sT.Brutal 900 Posted November 7, 2023 And how do you think the server would address those parameters? Share this post Link to post
Angus Robertson 574 Posted November 7, 2023 Quote And how do you think the server would address those parameters? The server can enumerate the parameters sequentially, rather than by accessing them by name, I just added a function to ICS to do exactly that, for diagnostic purposes. But comma separated values could be used as an array. It all depends on what the server expects, and it may not follow normal standards. Angus Share this post Link to post
Joe Sansalone 6 Posted November 7, 2023 The server is expecting same name parameter multiple times. But the TRestRequest.Params don't support adding the same parameter name again. Share this post Link to post
Uwe Raabe 2057 Posted November 7, 2023 Have you tried using the parameterless AddItem function overload and set the Name, Value and Kind in its result? Share this post Link to post
Joe Sansalone 6 Posted November 7, 2023 ok, I'll try the parameterless AddItem function ... thanks. Share this post Link to post
mvanrijnen 123 Posted November 7, 2023 (edited) 2 hours ago, Uwe Raabe said: Have you tried using the parameterless AddItem function overload and set the Name, Value and Kind in its result? It searches for the param with the name, and changes the value (and other properties of the parameter) I don't think this is possible with the default parameters in the TRestRequest. You have to fetch the TRestRequest parameter and use the .AddValue method i think. Edited November 7, 2023 by mvanrijnen Share this post Link to post
Uwe Raabe 2057 Posted November 7, 2023 34 minutes ago, mvanrijnen said: It searches for the param with the name, and changes the value (and other properties of the parameter) It doesn't even get a name to search for: function TRESTRequestParameterList.AddItem: TRESTRequestParameter; begin Result := Add as TRESTRequestParameter; end; Share this post Link to post
mvanrijnen 123 Posted November 7, 2023 (edited) 14 minutes ago, Uwe Raabe said: It doesn't even get a name to search for: function TRESTRequestParameterList.AddItem: TRESTRequestParameter; begin Result := Add as TRESTRequestParameter; end; Which Delphi version? In 11.3 there are a couple of overloads, but not that "overload version"? found it 🙂 overread the parameterless in your post that in combination with the .AddValue would be the solution Edited November 7, 2023 by mvanrijnen Share this post Link to post
Joe Sansalone 6 Posted November 8, 2023 I tried and it's not working. Is there a way to output the HTTP request text? The actual text that is being sent for the whole request? 1 Share this post Link to post
mvanrijnen 123 Posted November 8, 2023 (edited) Best way is to use a proxy, for a list see for example: mitmproxy Alternatives: Top 10 HTTP(S) & Web Debuggers | AlternativeTo ( i use mitm and/or fiddler, charles is also mentioned by @Uwe Raabe i believe) let mee see if i can capture some output for this. Here it works like a charm..... var ...... prm : TRESTRequestParameter; begin ..... req := TRESTRequest.Create(nil); try req.Client := FRestClient; req.Method := TRESTRequestMethod.rmPost; req.Resource := cExtensionResource; ..... prm := req.Params.AddItem(); prm.Name := 'testmultivalue'; prm.AddValue('Value_1'); prm.AddValue('Value_2'); prm.AddValue('Value_3'); prm.AddValue('Value_A'); req.Execute(); ..... don't mind the 400 error, i just changed a get into a post to try. Edited November 8, 2023 by mvanrijnen Share this post Link to post
Joe Sansalone 6 Posted November 8, 2023 I understand. BUT, I need: MediaUrl=value1&MediaUrl=value2&MediaUrl=value3 same parameter multiple times. Share this post Link to post
mvanrijnen 123 Posted November 8, 2023 Don ;t think thats possible with the Params property, it all ends up merging the diffentt params from client/request etc, and there they get overwritten when having the same name. You have to fill your request body by hand then i think. Share this post Link to post
Uwe Raabe 2057 Posted November 8, 2023 21 minutes ago, mvanrijnen said: You have to fill your request body by hand then i think. I guess the problem that these parameters are in the URL query. Share this post Link to post
Joe Sansalone 6 Posted November 10, 2023 OK, I got it to work via: tempBody := 'Param1=' + value1 + '&' + 'Param2=' + value2 + '&' ... etc; // build the parameters with & in-between each parameter RestRequest.Params.AddItem('Body1234', tempBody, pkREQUESTBODY, [poDoNotEncode]); // notice that there needs to be a unique name even for the entire body of parameters. Share this post Link to post