[#boost-urls-url_view_base-encoded_host_and_port]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/url_view_base.adoc[url&lowbar;view&lowbar;base]::encoded&lowbar;host&lowbar;and&lowbar;port
:relfileprefix: ../../../
:mrdocs:

Return the host and port

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/pct_string_view.adoc[pct&lowbar;string&lowbar;view]
encoded&lowbar;host&lowbar;and&lowbar;port() const noexcept;
----

== Description

If an authority is present, this function returns the host and optional port as a string, which may be empty&period; Otherwise it returns an empty string&period; The returned string may contain percent escapes&period;

== Example

[,cpp]
----
assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" );
----
== Complexity

Constant&period;

== Exception Safety

Throws nothing&period;

== BNF

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

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

== Return Value

The host and port portion of the url&period;

== See Also

xref:boost/urls/url_view_base/has_port.adoc[`has&lowbar;port`], xref:boost/urls/url_view_base/port.adoc[`port`], xref:boost/urls/url_view_base/port_number.adoc[`port&lowbar;number`]&period;


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