<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ## http 模塊 demo ``` //main.js var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, { 'Content-Type': 'text-plain' }); response.end('Hello World\n'); }).listen(8124); ``` `> node main.js ` 通過`http://loalhost:8124`訪問 > 在Linux系統下,監聽1024以下端口需要root權限。因此,如果想監聽80或443端口的話,需要使用sudo命令啟動程序。 ### 客戶端訪問 1. post ``` var http = require("http"); var options = { hostname: 'www.example.com', port: 80, path: '/upload', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; var request = http.request(options, function (response) { console.log(response); }); request.write('Hello World'); request.end(); ``` 2. get `http.get('http://www.example.com/', function (response) {});` ``` var http = require("http"); http.get('http://localhost:8124/', function (response) { var body = []; console.log(response.statusCode); //200 console.log(response.headers); //打印頭信息 response.on('data', function (chunk) { body.push(chunk); }); response.on('end', function () { body = Buffer.concat(body); console.log(body.toString()); //網址返回內容 }); }); ``` ## HTTPS 模塊 1. 創建https 的服務器 ``` var options = { key: fs.readFileSync('./ssl/default.key'), cert: fs.readFileSync('./ssl/default.cer') }; var server = https.createServer(options, function (request, response) { // ... }); ``` 2. 客戶端 訪問https ``` var options = { hostname: 'www.example.com', port: 443, path: '/', method: 'GET', rejectUnauthorized:false //可是非頒發機構 頒發的 證書安全問題 不進行提示 }; var request = https.request(options, function (response) {}); request.end(); ``` ## URL 模塊 1.` url.parse` 把url 字符串轉為對象 ``` url.parse('http://user:pass@host.com:8080/p/a/t/h?query=string#hash'); /* => { protocol: 'http:', auth: 'user:pass', host: 'host.com:8080', port: '8080', hostname: 'host.com', hash: '#hash', search: '?query=string', query: 'query=string', pathname: '/p/a/t/h', path: '/p/a/t/h?query=string', href: 'http://user:pass@host.com:8080/p/a/t/h?query=string#hash' } */ ``` `.parse` 第二個參數為true 則`query`字段轉為對象 2. `url.format` 把url對象轉為url字符串 ``` url.format({ protocol: 'http:', host: 'www.example.com', pathname: '/p/a/t/h', search: 'query=string' }); //http://www.example.com/p/a/t/h?query=string ``` 3. `url.resolve` ```js url.resolve('http://www.example.com/foo/bar', '../baz'); //http://www.example.com/baz ``` ## Query String 模塊 ```js querystring.parse('foo=bar&baz=qux&baz=quux&corge'); //{ foo: 'bar', baz: ['qux', 'quux'], corge: '' } querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' }); //'foo=bar&baz=qux&baz=quux&corge=' ``` ## zlib > [參考](http://nqdeng.github.io/7-days-nodejs/#4.2.5) zlib模塊提供了數據壓縮和解壓的功能。當我們處理HTTP請求和響應時,可能需要用到這個模塊。 ## Net
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看