Difference between http://+:8080/ and http://*:808

2020-02-13 10:35发布

问题:

What are the differences between these two prefixes in terms of HttpListener or any other?

http://+:8080/

http://*:8080/

回答1:

http://*:8080/: Receive all HTTP requests on port 8080 that are not already being handled by some other HttpListener.

http://+:8080/: Receive all HTTP requests on port 8080 even if they're already handled by another HttpListener.



回答2:

In addition to @Paulpro's great answer, the link posted by @rownage (see this answer) provides some more information about the difference:

Strong wildcard (Plus Sign +)

When the host element of a UrlPrefix consists of a single plus sign (+), the UrlPrefix matches all possible host names in the context of its scheme, port and relativeURI elements, and falls into the strong wildcard category.

A strong wildcard is useful when an application needs to serve requests addressed to one or more relativeURIs, regardless of how those requests arrive on the machine or what site they specify in their Host headers. Use of a strong wildcard in this situation avoids the need to specify an exhaustive list of host and/or IP-addresses.

Weak wildcard (Asterisk *)

When an asterisk (*) appears as the host element, then the UrlPrefix falls into the weak wildcard category. This kind of UrlPrefix matches any host name associated with the specified scheme, port and relativeURI that has not already been matched by a strong-wildcard, explicit, or IP-bound weak-wildcard UrlPrefix.

This host specification can be used as a default catch-all in some circumstances, or can be used to specify a large section of URL namespace without having to use many UrlPrefixes.