#1 2013-07-19 04:12:04

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Parsing of GET Parameters in THttpApiServer

Before trying to reinvent the wheel and doing manual parsing of Ctxt.URL, is there a ready function or property that (pre)parses GET parameters into, say, a TStringList?

Thanks!

Offline

#2 2013-07-19 15:56:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Parsing of GET Parameters in THttpApiServer

Please take a look at method-based services in the SAD pdf.

There are already functions for URI decoding.
See all UrlDecode*() functions in SynCommons.pas.

Offline

#3 2013-07-20 05:45:26

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Re: Parsing of GET Parameters in THttpApiServer

Hi Arnaud, thanks for the reply.

Yup, had a look at the UrlDecode* functions. I reckon the easiest way out is to use UrlDecodeNextNameValue and assign the pair to a StringList/Dictionary eh? Or perhaps to take the parameter portion of the URI, remove the '?', perform a string replace of all & into CRLF, and assign it directly to a StringList? I guess both a do-able.

The reason I asked this is because I would like to allow for optional parameters and to pre-assign default values to those that are not set.

Thanks again Arnaud, for the fantastic framework!

Offline

#4 2013-07-20 07:05:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Parsing of GET Parameters in THttpApiServer

IMHO a TStringList/Dictionary is not mandatory.
The UrlDecode*() functions allow to define a set of variables in a loop, with minimal performance impact.
You can assign default values by setting some values before the loop.

Offline

Board footer

Powered by FluxBB