How to Obtain the GET request to get the data query, url related pathname

When the get request is sent to the server in the data on the url.

And by parsing the url.

url.parse (req.url).      url.parse: an urlObject url address into a second parameter write true if the query parsed into represents an object    

 

query:
'wd=%E5%8D%83%E9%94%8B&rsv_spt=1&rsv_iqid=0xc701ea9f0005f97f&issp=1&f=3&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=9&rsv_sug1=6&rsv_sug7=100&rsv_sug2=0&prefixsug=qianfeng&rsp=5&inputT=3318&rsv_sug4=3841',

 

url.parse(req.url,true).

query:

[Object: null prototype] {name = 'zhangsan', age = 16} is exactly get the requested data
 

pathname 

 

pathname: '/s',
path :( equal pathname + query)
 '/s?wd=%E5%8D%83%E9%94%8B&rsv_spt=1&rsv_iqid=0xc701ea9f0005f97f
query string
'wd=%E5%8D%83%E9%94%8B&rsv_spt=1&rsv_iqid=0xc701ea9f0005f97f'’
 
req.url entire path, and the port is the pathname / user / s etc.
 

Guess you like

Origin www.cnblogs.com/shenlan88/p/11070322.html
Recommended