Get the content submitted by the form

The first result: 

let url = require("url");
let obj = url.parse('/pinglun?name=1234&value=wererr'); 

    console.log(obj);

The above results are as follows:

Url {
  protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: '?name=1234&value=wererr',      
  query: 'name=1234&value=wererr',        
  pathname: '/pinglun',
  path: '/pinglun?name=1234&value=wererr',
  href: '/pinglun?name=1234&value=wererr' 
}

The second result:

let url = require("url");
let obj = url.parse('/pinglun?name=1234&value=wererr'); 
    obj = url.parse('/pinglun?name=1234&value=wererr',true);
    console.log(obj);

The results are as follows:

 Url {
    protocol: null,
    slashes: null,
    auth: null,
    host: null,
    port: null,
    hostname: null,
    hash: null,
    search: '?name=1234&value=wererr',
    query: [Object: null prototype] { name: '1234', value: 'wererr' },
    pathname: '/pinglun',
    path: '/pinglun?name=1234&value=wererr',
    href: '/pinglun?name=1234&value=wererr'
    }
 

 

Summary: I don’t know if you have found the two differences above. Yes, the first is that the number of parameters in parse() is different, and the second is that the results in the query are different: the first is a string and the second is an object. , For us, we prefer the second one,

Reasons: (1) For objects, we can always find a way to get the contents

           (2) Compared with others, I think the difficulty of obtaining the content inside the object is relatively low 

Guess you like

Origin blog.csdn.net/L_Z_jay/article/details/113049134