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

Set the port

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/url.adoc[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

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

== Return Value

`&ast;this`

== Parameters

[cols="1,4"]
|===
|Name|Description

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

== See Also

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


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