{"id":1025,"date":"2023-03-12T09:35:43","date_gmt":"2023-03-12T01:35:43","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1025"},"modified":"2023-04-29T13:13:47","modified_gmt":"2023-04-29T05:13:47","slug":"nodejs-urlencode-module-url-encryption-and-decryption","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/nodejs-urlencode-module-url-encryption-and-decryption\/","title":{"rendered":"Nodejs urlencode\u6a21\u5757url\u52a0\u5bc6\u89e3\u5bc6"},"content":{"rendered":"<h2>\u5b89\u88c5<\/h2>\n<pre><code>npm install urlencode<\/code><\/pre>\n<p><!-- more --><\/p>\n<h2>\u4f7f\u7528<\/h2>\n<pre><code class=\"language-javascript\">var urlencode = require(&#039;urlencode&#039;);\n\nconsole.log(urlencode(&#039;\u82cf\u5343&#039;)); \/\/ default is utf8\nconsole.log(urlencode(&#039;\u82cf\u5343&#039;, &#039;gbk&#039;)); \/\/ &#039;%CB%D5%C7%A7&#039;\n\n\/\/ decode gbk\nurlencode.decode(&#039;%CB%D5%C7%A7&#039;, &#039;gbk&#039;); \/\/ &#039;\u82cf\u5343&#039;\n\n\/\/ parse gbk querystring\nurlencode.parse(&#039;nick=%CB%D5%C7%A7&#039;, {charset: &#039;gbk&#039;}); \/\/ {nick: &#039;\u82cf\u5343&#039;}\n\n\/\/ stringify obj with gbk encoding\nvar str = &#039;x[y][0][v][w]=&#039; + urlencode(&#039;\u96fe\u7a7a&#039;, &#039;gbk&#039;); \/\/ x[y][0][v][w]=%CE%ED%BF%D5\nvar obj =  {&#039;x&#039; : {&#039;y&#039; : [{&#039;v&#039; : {&#039;w&#039; : &#039;\u96fe\u7a7a&#039;}}]}};\nurlencode.stringify(obj, {charset: &#039;gbk&#039;}).should.equal(str);<\/code><\/pre>\n<p>\u53c2\u8003\u94fe\u63a5\uff1a <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/www.npmjs.com\/package\/urlencode\">https:\/\/www.npmjs.com\/package\/urlencode<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5 npm install urlencode \u4f7f\u7528 var urlencode = require(&#038;#0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[280],"class_list":["post-1025","post","type-post","status-publish","format-standard","hentry","category-node","tag-urlencode"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1025"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1025\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}