Skip to content

How to get query parameters?

阿超 edited this page Oct 1, 2018 · 2 revisions

If the requestd URL is http://xxx.xx/xx/xx/?name=demoName&id=demoId

auto name = ctx.request->getQueryParam("name");
auto id =  ctx.request->getQueryParam("id");

the name is string demoName and id is string demoId.

If the query string parameter does not exist, then an empty string is returned. Such as the following:

the requested URL is http://xx.xx/xx/?name=demoName

auto id = ctx.request->getQueryParam("id");  // id ==""