我想读取一个url
我拥有的字符串的端口。我发现您可以使用urlstring
作为参数创建一个新的URL对象。然后,您可以调用该对象的port属性来获取的端口urlstring
。
我的港口url
是443
。如果我将字符串443作为URL对象的端口,则该端口的属性url-object
为""
。如果我选择其他数字作为端口,则可以正常工作。
有人知道为什么会这样吗?
这是一个代码片段:
const URL_STRING1 = "https://example.com:443/";
let url1 = new URL(URL_STRING1);
console.log(url1.port);
const URL_STRING2 = "https://example.com:442/";
let url2 = new URL(URL_STRING2);
console.log(url2.port);
const URL_STRING3 = "https://example.com:444/";
let url3 = new URL(URL_STRING3);
console.log(url3.port);
443
是默认端口 https
....
---> Set url’s port to null, if port is url’s scheme’s default port, and to port otherwise.
^^^^^^^^^^^^^^^^^^^^^
....
Default scheme reference for full specs
A special scheme is a scheme listed in the first column of the following table. A default port is a special scheme’s optional corresponding port and is listed in the second column on the same row.
scheme port
"ftp" 21
"file"
"http" 80
"https" 443
"ws" 80
"wss" 443
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句