{"id":6314,"date":"2023-01-07T12:34:29","date_gmt":"2023-01-07T04:34:29","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6314"},"modified":"2023-01-07T12:34:29","modified_gmt":"2023-01-07T04:34:29","slug":"%e4%ba%86%e8%a7%a3%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8node-js%e4%b8%ad%e7%9a%84url%e6%a8%a1%e7%b5%84%e8%a7%a3%e6%9e%90%e5%92%8c%e6%a0%bc%e5%bc%8f%e5%8c%96url","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/node-js\/%e4%ba%86%e8%a7%a3%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8node-js%e4%b8%ad%e7%9a%84url%e6%a8%a1%e7%b5%84%e8%a7%a3%e6%9e%90%e5%92%8c%e6%a0%bc%e5%bc%8f%e5%8c%96url\/","title":{"rendered":"\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Node.js\u4e2d\u7684URL\u6a21\u7d44\u89e3\u6790\u548c\u683c\u5f0f\u5316URL"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Node.js, url, \u6a21\u5757, \u89e3\u6790, \u683c\u5f0f\u5316, URL\"><\/p>\n<h1>\u5982\u4f55\u5728 Node.js \u4e2d\u4f7f\u7528 &#8216;url&#8217; \u6a21\u5757\u89e3\u6790\u548c\u683c\u5f0f\u5316 URL\uff1f<\/h1>\n<p>Node.js \u662f\u4e00\u500b\u5ee3\u53d7\u6b61\u8fce\u7684 JavaScript \u74b0\u5883\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u958b\u767c\u5404\u7a2e\u61c9\u7528\u7a0b\u5f0f\uff0c\u5305\u62ec\u7db2\u7ad9\u548c\u670d\u52d9\u5668\u7aef\u61c9\u7528\u7a0b\u5f0f\u3002\u5728 Node.js \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 &#8216;url&#8217; \u6a21\u5757\u4f86\u89e3\u6790\u548c\u683c\u5f0f\u5316 URL\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f URL\uff1f<\/h2>\n<p>URL\uff08\u7d71\u4e00\u8cc7\u6e90\u5b9a\u4f4d\u5668\uff09\u662f\u4e00\u7a2e\u7528\u65bc\u6307\u5b9a\u7db2\u7d61\u4e0a\u7684\u8cc7\u6e90\u7684\u5b57\u7b26\u4e32\u3002\u5b83\u53ef\u4ee5\u6307\u5b9a\u7db2\u9801\uff0c\u5716\u50cf\uff0c\u6587\u4ef6\u7b49\u3002URL \u5305\u542b\u4e86\u8a72\u8cc7\u6e90\u7684\u4f4d\u7f6e\u548c\u5982\u4f55\u8a2a\u554f\u5b83\u7684\u8a73\u7d30\u4fe1\u606f\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 &#8216;url&#8217; \u6a21\u5757\uff1f<\/h2>\n<p>\u8981\u4f7f\u7528 &#8216;url&#8217; \u6a21\u5757\uff0c\u9996\u5148\u9700\u8981\u5c0e\u5165\u5b83\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst url = require('url');\n<\/pre>\n<p>\u7136\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528 &#8216;url&#8217; \u6a21\u5757\u7684 &#8216;parse&#8217; \u65b9\u6cd5\u4f86\u89e3\u6790 URL\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst myURL = url.parse('https:\/\/example.com\/foo\/bar?foo=bar#baz');\n<\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u78bc\u5c07\u6703\u8fd4\u56de\u4e00\u500b\u5c0d\u8c61\uff0c\u5176\u4e2d\u5305\u542b\u4e86 URL \u7684\u5404\u500b\u90e8\u5206\uff1a<\/p>\n<pre class=\"brush: javascript\">\n{\n  protocol: 'https:',\n  slashes: true,\n  auth: null,\n  host: 'example.com',\n  port: null,\n  hostname: 'example.com',\n  hash: '#baz',\n  search: '?foo=bar',\n  query: 'foo=bar',\n  pathname: '\/foo\/bar',\n  path: '\/foo\/bar?foo=bar',\n  href: 'https:\/\/example.com\/foo\/bar?foo=bar#baz'\n}\n<\/pre>\n<p>\u53e6\u5916\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 &#8216;url&#8217; \u6a21\u5757\u7684 &#8216;format&#8217; \u65b9\u6cd5\u4f86\u683c\u5f0f\u5316 URL\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst myURL = url.format({\n  protocol: 'https:',\n  hostname: 'example.com',\n  pathname: '\/foo\/bar',\n  search: '?foo=bar',\n  hash: '#baz'\n});\n\nconsole.log(myURL);\n\/\/ https:\/\/example.com\/foo\/bar?foo=bar#baz\n<\/pre>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728 Node.js \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 &#8216;url&#8217; \u6a21\u5757\u4f86\u89e3\u6790\u548c\u683c\u5f0f\u5316 URL\u3002\u5b83\u63d0\u4f9b\u4e86 &#8216;parse&#8217; \u548c &#8216;format&#8217; \u65b9\u6cd5\uff0c\u53ef\u4ee5\u7528\u65bc\u5c07 URL \u89e3\u6790\u70ba\u5c0d\u8c61\uff0c\u4e26\u5c07\u5c0d\u8c61\u683c\u5f0f\u5316\u70ba URL\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u5728Node.js\u4e2d\uff0c\u4f7f\u7528URL\u6a21\u7d44\u53ef\u4ee5\u89e3\u6790\u548c\u683c\u5f0f\u5316URL\uff0c\u4e26\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684API\u4f86\u64cd\u4f5cURL\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u64cd\u4f5cURL\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Node.js\u4e2d\u7684URL\u6a21\u7d44\u89e3\u6790\u548c\u683c\u5f0f\u5316URL\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[193,192],"tags":[191,190],"class_list":["post-6314","post","type-post","status-publish","format-standard","hentry","category-node","category-node-js","tag-node","tag-node-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1DQ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=6314"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6314\/revisions"}],"predecessor-version":[{"id":6315,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6314\/revisions\/6315"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}