:relfileprefix: ../../../
[#boost-urls-url-set_port]

= xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/url.adoc[pass:[url]]::set_port


Set the port


== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url.hpp#L458[boost/url/url.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
xref:boost/urls/url.adoc[url]&
set_port(core::string_view s);
----

== Description


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

=== 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.
Calls to allocate may throw.
Exceptions thrown on invalid input.

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

=== Specification

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



== Exceptions

|===
| Name | Thrown on

| `system_error`
| 
`s` does not contain a valid port.

|===



== Parameters

|===
| Name | Description 

| *s*
| 
The port string to set.

|===




== See Also


xref:boost/urls/url_base/remove_port.adoc[remove_port]
,
xref:boost/urls/url_base/set_port.adoc[set_port]
.



