[#boost-urls-url_base-set_encoded_query] = xref:boost/urls/url_base/set_encoded_query.adoc[boost::urls::url_base::set_encoded_query] :relfileprefix: ../../../ :mrdocs: Set the query == Synopsis Declared in `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url_base.hpp#L2076[boost/url/url_base.hpp]>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:boost/urls/url_base.adoc[url_base]& set_encoded_query(xref:boost/urls/pct_string_view.adoc[pct_string_view] s); ---- == Description This sets the query to the string, which may contain percent‐escapes and can be empty. An empty query is distinct from having no query. Escapes in the string are preserved, and reserved characters in the string are percent‐escaped in the result. == Example [,cpp] ---- assert( url( "http://example.com" ).set_encoded_query( "id=42" ).encoded_query() == "id=42" ); ---- == Postconditions [,cpp] ---- this->has_query() == true && this->query() == decode_view( s ); ---- == Exception Safety Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input. == BNF [,cpp] ---- query = *( pchar / "/" / "?" ) query-param = key [ "=" value ] query-params = [ query-param ] *( "&" query-param ) ---- == Specification * https://datatracker.ietf.org/doc/html/rfc3986#section-3.4[] * https://en.wikipedia.org/wiki/Query_string[] == Exceptions [cols=2] |=== | Name | Thrown on | `system_error` | `s` contains an invalid percent‐encoding. |=== == Return Value `*this` == Parameters [cols=2] |=== | Name | Description | *s* | The string to set. |=== == See Also xref:boost/urls/url_base/encoded_params-0b.adoc[`encoded_params`], xref:boost/urls/url_base/params-0c1.adoc[`params`], xref:boost/urls/url_base/remove_query.adoc[`remove_query`], xref:boost/urls/url_base/set_query.adoc[`set_query`]. [.small]#Created with https://www.mrdocs.com[MrDocs]#