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

Set the port

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/url.adoc[url]&
set&lowbar;port&lowbar;number(std::uint16&lowbar;t n);
----

== Description

The port is set to the specified integer&period;

== Example
[,cpp]
----
assert( url( "http://www.example.com" ).set_port_number( 8080 ).authority().buffer() == "www.example.com:8080" );
----
== Postconditions
[,cpp]
----
this->has_authority() == true && this->has_port() == true && this->port_number() == n
----
== Complexity
Linear in `this&hyphen;&gt;size()`&period;

== Exception Safety
Strong guarantee&period; Calls to allocate may throw&period;

== BNF
[,cpp]
----
authority     = [ userinfo "@" ] host [ ":" port ]

port          = *DIGIT
----
== Specification
* https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3[]

== Return Value

`&ast;this`

== Parameters

[cols=2]
|===
| Name
| Description
| *n*
| The port number to set&period;
|===

== See Also

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


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