亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

??
url
parse(urlString, parseQueryString, slashesDenoteHost)
format(urlObject)
resolve(from, to)
querystring
parse(str, sep, eq, options)
stringify(obj, sep, eq, options)
????? ???? ? ?? ?? ????? parseQueryString ? slashesDenoteHos????parseQueryString ??? ?????. false? ?? urlObject.query? nick=%E4%B8%AD%E6%96%87? ?? ?? ???? ?? ????? ??? ?????. ?? ????? ????. parseQueryString? true? ?? urlObject.query? ?????. > { nick: '???' }, ?? `??????. ??%%PRE_BLOCK_8%%??Node? url ??? querystring ??? ?? ???? ?????.????slashesDenoteHos: (???? false) true? ?? ? ?? >/ /randy/nick? randy? ??? ???? ?????. false?? randy< /code> code>? pathname? ??? ?????. ?????? ?? ? ??? ??? ???? ?? ?? ????. ?? ?? ????? ???? ?? ????. ??rrreee??Node? url ??? querystring ??? ?? ???? ?????.??< h4 data-id="heading-3">format(urlObject)" >parse(urlString, parseQueryString, slashesDenoteHost)??? ?? url ???? ???? ???? ??? object? ?? ?????. ??%%PRE_BLOCK_7%%??Output????Node? url ??? querystring ??? ?? ???? ?????.????? ???? ? ?? ?? ????? parseQueryString ? slashesDenoteHos????parseQueryString ??? ?????. false? ?? urlObject.query? nick=%E4%B8%AD%E6%96%87? ?? ?? ???? ?? ????? ??? ?????. ?? ????? ????. parseQueryString? true? ?? urlObject.query? ?????. > { nick: '???' }, ?? `??????. ??%%PRE_BLOCK_8%%??Node? url ??? querystring ??? ?? ???? ?????.????slashesDenoteHos: (???? false) true? ?? ? ?? >/ /randy/nick? randy? ??? ???? ?????. false?? randy< /code> code>? pathname? ??? ?????. ?????? ?? ? ??? ??? ???? ?? ?? ????. ?? ?? ????? ???? ?? ????. ??rrreee??Node? url ??? querystring ??? ?? ???? ?????.??< h4 data-id="heading-3">format(urlObject)
? ? ????? JS ???? Node? url ??? querystring ??? ?? ???? ?????.

Node? url ??? querystring ??? ?? ???? ?????.

Feb 23, 2023 pm 07:39 PM
??? ?? node.js ??

Node? url ??? querystring ??? ?? ???? ?????.

url ??? querystring ??? ? ?? ?? ??? URL ?? ?????. node ??? ??? ? ?? ?????. url模塊和querystring模塊是非常重要的兩個URL處理模塊。在做node服務端的開發(fā)時會經(jīng)常用到。

url

在介紹url模塊之前我們先來一張圖,看懂了這張圖對于url這個模塊你就基本上沒什么問題了。

Node? url ??? querystring ??? ?? ???? ?????.

我們來解釋下各自的含義

  • protocol:協(xié)議,需要注意的是包含了:,并且是小寫的?!鞠嚓P教程推薦:nodejs視頻教程、編程教學
  • slashes:如果:后面跟了兩個//,那么為true。
  • auth:認證信息,如果有密碼,為usrname:passwd,如果沒有,則為usrname。注意,這里區(qū)分大小寫。
  • host:主機名。注意包含了端口,比如ke.qq.com:8080,并且是小寫的。
  • hostname:主機名,不包含端口,并且是小寫的。
  • port: 端口號。
  • path:路徑部分,包含search部分。
  • pathname:路徑部分,不包含search部分。
  • search:查詢字符串,注意,包含了?,此外,值是沒有經(jīng)過decode的。
  • query:字符串 或者 對象。如果是字符串,則是search去掉?,其余一樣;如果是對象,那么是decode過的。
  • hash:哈希部分,注意包含了#。
  • href:原始的地址。不過需要注意的是,protocol、host會被轉成小寫字母。

下面我們來講解下它的三個常用方法

parse(urlString, parseQueryString, slashesDenoteHost)

該方法將url字符串,解析成object,便于開發(fā)者進行操作。

const url = require(&amp;quot;url&amp;quot;);

const str = &amp;quot;http://user:password@randy.com:8080/index.html?nick=%E4%B8%AD%E6%96%87#part=1&amp;quot;;

const obj = url.parse(str);
console.log(obj);

輸出

Node? url ??? querystring ??? ?? ???? ?????.

該方法還支持傳遞另外兩個參數(shù),parseQueryStringslashesDenoteHos

parseQueryString:(默認為false)如為false,則urlObject.query為未解析的字符串,比如nick=%E4%B8%AD%E6%96%87,且對應的值不會decode;如果parseQueryString為true,則urlObject.queryobject,比如{ nick: &amp;amp;#39;中文&amp;amp;#39; },且值會被`decode;

const url = require(&amp;quot;url&amp;quot;);

const str = &amp;quot;http://user:password@randy.com:8080/index.html?nick=%E4%B8%AD%E6%96%87#part=1&amp;quot;;

const obj2 = url.parse(str, true);
console.log(obj2);

Node? url ??? querystring ??? ?? ???? ?????.

slashesDenoteHos:(默認為false)如果為true,那么類似//randy/nick里的randy就會被認為是hostname;如果為false,則randy被認為是pathname的一部分。

光看起來可能不太理解這句話的含義,下面筆者舉個例子我相信你們就明白了。

const str2 = &amp;quot;//randy/nick&amp;quot;;

const obj3 = url.parse(str2, true, false);
console.log(obj3);
const obj4 = url.parse(str2, true, true);
console.log(obj4);

Node? url ??? querystring ??? ?? ???? ?????.

format(urlObject)

這個方法就是parse的反向操作。將對象轉成url字符串。

const pathObj = {
  protocol: &amp;quot;http:&amp;quot;,
  slashes: true,
  auth: &amp;quot;user:password&amp;quot;,
  host: &amp;quot;randy.com:8080&amp;quot;,
  port: &amp;quot;8080&amp;quot;,
  hostname: &amp;quot;randy.com&amp;quot;,
  hash: &amp;quot;#part=1&amp;quot;,
  search: &amp;quot;?nick=%E4%B8%AD%E6%96%87&amp;quot;,
  query: &amp;quot;nick=%E4%B8%AD%E6%96%87&amp;quot;,
  pathname: &amp;quot;/index.html&amp;quot;,
  path: &amp;quot;/index.html?nick=%E4%B8%AD%E6%96%87&amp;quot;,
  href: &amp;quot;http://user:password@randy.com:8080/index.html?nick=%E4%B8%AD%E6%96%87#part=1&amp;quot;,
};

console.log(url.format(pathObj)); // http://user:password@randy.com:8080/index.html?nick=%E4%B8%AD%E6%96%87#part=1

resolve(from, to)

該方法用于解析相對于基本URL的目標URL。

console.log(url.resolve(&amp;quot;/one/two/three&amp;quot;, &amp;quot;four&amp;quot;)); // /one/two/four
console.log(url.resolve(&amp;quot;http://example.com/&amp;quot;, &amp;quot;/one&amp;quot;)); // http://example.com/one
console.log(url.resolve(&amp;quot;http://example.com/one&amp;quot;, &amp;quot;/two&amp;quot;)); // http://example.com/two
console.log(url.resolve(&amp;quot;http://example.com/one/ddd/ddd/ddd&amp;quot;, &amp;quot;./two&amp;quot;)); // http://example.com/one/ddd/ddd/two
console.log(url.resolve(&amp;quot;http://example.com/one/ddd/ddd/ddd&amp;quot;, &amp;quot;../two&amp;quot;)); // http://example.com/one/ddd/two
console.log(url.resolve(&amp;quot;http://example.com/one/ddd/ddd/ddd&amp;quot;, &amp;quot;.../two&amp;quot;)); // http://example.com/one/ddd/ddd/.../two

querystring

querystring這個模塊,也是用來做url查詢參數(shù)的解析。這里我們重點分析下它的parsestringify兩個方法。

parse(str, sep, eq, options)

parse是將查詢字符串轉成對象類型,并且也會decode。

const querystring = require(&amp;quot;querystring&amp;quot;);

const str = &amp;quot;nick=randy&amp;amp;age=24&amp;amp;nick2=%E4%B8%AD%E6%96%87&amp;quot;;
const obj = querystring.parse(str);
console.log(obj); // { nick: &amp;amp;#39;randy&amp;amp;#39;, age: &amp;amp;#39;24&amp;amp;#39;, nick2: &amp;amp;#39;中文&amp;amp;#39; }

下面我們再來看看它的第二和第三個參數(shù)。其實相當于可以替換&amp;amp;、=為自定義字符,下面筆者舉個例子就很快明白了。

const str1 = &amp;quot;name-randy|country-cn&amp;quot;;
const obj1 = querystring.parse(str1);
console.log(obj1); // { &amp;amp;#39;name-randy|country-cn&amp;amp;#39;: &amp;amp;#39;&amp;amp;#39; }
const obj2 = querystring.parse(str1, &amp;quot;|&amp;quot;, &amp;quot;-&amp;quot;);
console.log(obj2); // { name: &amp;amp;#39;randy&amp;amp;#39;, country: &amp;amp;#39;cn&amp;amp;#39; }

相當于把&amp;替換成了|,把=替換成了-。筆者感覺配到這種情況應該不多。

stringify(obj, sep, eq, options)

這個方法就是上面parse

url

url ??? ???? ?? ? ??? url? ?? ??? ???? ???? ?? ??? ?? ?????. ????? ? ???? ??? ??? ????.

Node? url ??? querystring ??? ?? ???? ?????.????us ??? ??? ??? ?????.??
  • ????: ???? :? ???? ??? ????? ?? ???? ???. [?? ?? ????: nodejs ??? ????, ????? ??]
  • ???: :? ??? ?? by //? 2? ??? true???.
  • auth: ?? ???, ????? ??? usrname:passwd, ??? usrname???. ????? ????? ?? ?????.
  • ???: ??? ??. ??? ke.qq.com:8080? ?? ???? ??????.
  • ??? ??: ??? ???? ??? ???? ??? ??????.
  • ??: ?? ??.
  • ??: ?? ??? ??? ?? ?????.
  • ???: ?? ??, ?? ?? ??.
  • ??: ?? ????? ?? ???? ????. ?? ?? ????? ????.
  • ??: ??? ?? ??. ????? search ?? ??? ???? ???? ???? ??????.
  • hash: ?? ??, #? ???? ????.
  • href: ?? ??. ?, protocol? host? ???? ????? ????? ????.
??? ?? ???? ??? ?????????

parse(urlString, parseQueryString, slashesDenoteHost)??? ?? url ???? ???? ???? ??? object? ?? ?????. ??
const obj3 = {
  nick: &amp;quot;randy&amp;quot;,
  age: &amp;quot;24&amp;quot;,
};
const str4 = querystring.stringify(obj3);
console.log(str4); // nick=randy&amp;amp;age=24
??Output????Node? url ??? querystring ??? ?? ???? ?????.????? ???? ? ?? ?? ????? parseQueryString ? slashesDenoteHos????parseQueryString ??? ?????. false
? ?? urlObject.query? nick=%E4%B8%AD%E6%96%87? ?? ?? ???? ?? ????? ??? ?????. ?? ????? ????. parseQueryString? true? ?? urlObject.query? ?????. > { nick: '???' }, ?? `??????. ??
const obj5 = {
  name: &amp;quot;randy&amp;quot;,
  country: &amp;quot;cn&amp;quot;,
};
const str6 = querystring.stringify(obj5, &amp;quot;|&amp;quot;, &amp;quot;-&amp;quot;);
console.log(str6); // name-randy|country-c
??Node? url ??? querystring ??? ?? ???? ?????.????slashesDenoteHos: (???? false) true? ?? ? ?? &gt;/ /randy/nick? randy? ??? ???? ?????. false?? randy&lt; /code&gt; code&gt;? &lt;code&gt;pathname? ??? ?????. ?????? ?? ? ??? ??? ???? ?? ?? ????. ?? ?? ????? ???? ?? ????. ??rrreee??Node? url ??? querystring ??? ?? ???? ?????.??< h4 data-id="heading-3">format(urlObject)

??? ???? ??? ?? ?????. ??? url ???? ?????. ??rrreee

resolve(from, to)

??? ??? ?? URL&lt;/code? ???? ??? ???? ? ?????. &gt; &lt;code&gt;URL. ??rrreee

querystring

??querystring ? ??? url ?? ????? ?? ???? ??? ?????. ???? parse? stringify?? ? ?? ??? ???? ? ??? ???. ??

parse(str, sep, eq, options)

??parse? ?? ???? ?? ???? ?????. , ???? ?????. ??rrreee?? ? ??? ? ?? ????? ???????. ??? &amp; ? =? ??? ?? ??? ??? ?? ????. ???? ??? ?? ???? ??? ??? ? ????. ??rrreee??&amp;? |? ???, =? -? ??? ?? ????. ??? ?? ??? ???? ??? ?????. ??

stringify(obj, sep, eq, options)

??? ??? ?? ?? ?? ?????. ?? ??? ?? ?????????rrreee??? ??? ?? ?? ??? ?????. ??
const obj5 = {
  name: &amp;quot;randy&amp;quot;,
  country: &amp;quot;cn&amp;quot;,
};
const str6 = querystring.stringify(obj5, &amp;quot;|&amp;quot;, &amp;quot;-&amp;quot;);
console.log(str6); // name-randy|country-c

更多node相關知識,請訪問:nodejs 教程!

? ??? Node? url ??? querystring ??? ?? ???? ?????.? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1597
29
PHP ????
1488
72
???
PHP? Vue: ????? ?? ??? ??? ?? PHP? Vue: ????? ?? ??? ??? ?? Mar 16, 2024 pm 12:09 PM

PHP? Vue: ????? ?? ??? ??? ?? ??? ???? ??? ???? ??? ????? ??? ?? ? ????? ????. ???? ? ??? ? ?????? ??? ?? ?? ??? ?? ? ???? ?? ??? ?? ???? ?? ????? ??? ??? ???? ??? ? ??? ?????? ???? ???. ????? ?? ??? ? ?? ??? ??? PHP? Vue.js? ?? ???? ??? ???? ? ? ????. ? ????? ??? ? ? ??? ? ? ???? ??? ? ??? PHP? Vue? ??? ??? ?? ??? ???????.

Go ?? ????? ?? ??: ????? ??? ?? ??? ?? Go ?? ????? ?? ??: ????? ??? ?? ??? ?? Mar 28, 2024 pm 01:06 PM

??? ???? ????? ??? Go ??? ??? ?? ???? ?? ?????. ??? Go ??? ????? ??? ????? ??? ?? ????. ??? ????? ??? Go ??? ???? ???? ??? ?? ??? ????? ??? ??? ??? ?? ????. ? ????? ????? ??? Go ??? ??? ? ?? ???? ???? ??? ? ??? ? ? ??? ? ??? ???? ?? ??? ?????. ???? ????? ????? ??? ?????? ???? ?? JavaScript, HTML, CSS? ???? ??? ????.

Django? ????????, ??????? ?? ??! Django? ????????, ??????? ?? ??! Jan 19, 2024 am 08:37 AM

Django? ?? ??? ??? ????? ???? Python?? ??? ? ?????? ????????. Django? ? ???????? Django? ??????? ?????? ?? ??? ???? ?????? ???? ??? ?? ?? ??? ?????. ?????? ???? ?? ?????? ?????? ????, ???? HTTP ????? ?? ???? ?????? ??? ????? ?????. ?????? ???? ???? ?????? ??? ????? ????? ???? ?? ???? ??? ????? ??, ??? ??? ??? ? ????.

C# ?? ?? ??: ????? ? ??? ?? ?? ?? C# ?? ?? ??: ????? ? ??? ?? ?? ?? Nov 23, 2023 am 10:13 AM

C# ????? ??? ?? ???? ????? ?????? ??? ??? ?????. ??? ???? ????? ???? ???? ?? ?????? ???? ?? ??? ?? ? ????? ???????. ? ????? C# ???? ?? ??? ?? ????? ???? ? ??? ?? ? ?? ??? ?? ? ??? ?? ?? ??? ?????. ????? ??? ??? ? ?????? ???? ?? ??? API ?????? ?? ??? ??? ? ????. ?????? ??? ?? ??? ???? ???? ???? ?? ??? ?? ?? ????? ??? ???? ????. ????? ???? ????? ??? ?????.

????? ???? ?? ?? ?? ????? ???? ?? ?? ?? Mar 19, 2024 pm 02:24 PM

????? ?? ????? ???? ??? HTML/CSS ??, JavaScript ??, ????? ? ?????, ???? ??, ???? ? ??? ??, ?? ???, ??? ??? ??, ????? ?????, ??? ??, ??? ?? ? ???. ??? ??? ???? ??? ??, ???? ??, ?? ??? ?? ??? ???? ?? ???????. ??? ???? ??? ??? ???? ??? ? ??? ?? ??? ?? ??? ??? ???? ???.

Django: ?????? ??? ??? ?? ??? ? ?? ??? ?????! Django: ?????? ??? ??? ?? ??? ? ?? ??? ?????! Jan 19, 2024 am 08:52 AM

Django: ?????? ??? ??? ?? ??? ? ?? ??? ?????! Django? ????? ?? ??? ? ?????? ????????. MVC, MTV? ??? ??? ? ?? ??? ??? ? ??? ??? ? ??????? ?? ??? ? ????. Django? ??? ??? ??? ?? ??? ????? ?????? ??? ???? ??? ??? ?? ??? ? ??? ??? ? ????. Django? ????? ??? ??? ??? ??? ???? ????? ???? ????? ??? ??? ????.

Golang? ????? ??? ??: Golang? ????? ???? ?? ??? ??? ?????. Golang? ????? ??? ??: Golang? ????? ???? ?? ??? ??? ?????. Mar 19, 2024 pm 06:15 PM

Golang? ????? ??? ??: Golang? ????? ???? ?? ??? ??? ????? ???? ?? ??? ?????. ???? ??? ??????? ??? ???? ?? ????? ??? ?? ? ????? ????. ? ????? ??? ??? ????? ??? Golang? ??? ??? ? ? ????. ? ????? Golang? ????? ??? ??? ????? ???? ?? ?? ??? ?? ????? ????? ???? ?????. ????? ???? Golang? ??? ????? ???? ??? ?? ????.

Golang ????? ??? ?? ?? Golang ????? ??? ?? ?? Jun 02, 2024 pm 09:37 PM

Go ?????? Go? ?? ?????? ???? ?? ??? ??(?: ? ?? ? ?????? ??)? ???? ?? ?? ?????. ?? ???? Go ??????? Gin(? ??), GORM(?????? ??) ? RESTful(API ??)? ?????. ????? HTTP ?? ?? ??? ???? ????, ???? ???? ?? ???? ?? ?? ?? ??? ???? ? ?????. ?? ??? ??? ???? ???? ?? ??? ?????. gorilla/sessions? ???? ??? ??? ? ????.

See all articles