:relfileprefix: ../../../
[#A75AB505AF9AFA7696BD30DF06E30FB740C9C360]

= Function url_base::set_port

pass:v,q[Set the port]


== Synopsis

Declared in header `</boost/url/url_base.hpp#L1565[boost/url/url_base.hpp,window=blank_]>`

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

== Description

pass:v,q[This port is set to the string, which] pass:v,q[must contain only digits or be empty.]
pass:v,q[An empty port string is distinct from]
pass:v,q[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
pass:v,q[Strong guarantee.]
pass:v,q[Calls to allocate may throw.]
pass:v,q[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)]



== Return Value

* `` 


== Parameters

|===
| Name | Type 

| *s*
| `string_view`

|===



