[#boost-urls-static_url-set_port-06]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/static_url.adoc[static&lowbar;url]::set&lowbar;port
:relfileprefix: ../../../
:mrdocs:


Set the port

== Synopsis


Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/static_url.hpp#L394[boost&sol;url&sol;static&lowbar;url&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/static_url.adoc[static&lowbar;url]&
set&lowbar;port(core::string&lowbar;view s);
----

== Description


This port is set to the string, which        must contain only digits or be empty&period;        An empty port string is distinct from        having no port&period;


=== Example

[,cpp]
----
assert( url( "http://www.example.com" ).set_port( "8080" ).authority().buffer() == "www.example.com:8080" );
----

=== Postconditions

[,cpp]
----
this->has_port() == true && this->port_number() == n && this->port() == std::to_string(n)
----

=== Exception Safety

Strong guarantee&period;        Calls to allocate may throw&period;        Exceptions thrown on invalid input&period;


=== BNF

[,cpp]
----
port          = *DIGIT
----

=== Specification

* link:https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3[            3&period;2&period;3&period; Port (rfc3986)]



== Exceptions


|===
| Name | Thrown on

| `system&lowbar;error`
| `s` does not contain a valid port&period;


|===

== Parameters


|===
| Name | Description

| *s*
| The port string to set&period;


|===

== See Also


xref:boost/urls/url_base/remove_port.adoc[remove&lowbar;port],            xref:boost/urls/url_base/set_port.adoc[set&lowbar;port]&period;






[.small]#Created with https://www.mrdocs.com[MrDocs]#
