## http模塊
http模塊是node提供當用戶要搭建 HTTP 服務器與客戶端的時候的一個內置模塊
### 1.http.createServer 服務端創建
~~~
const http = require('http');
const server = http.createServer((req, res) => {
res.end();
});
server.listen(8000)
~~~
方法
* server.listen()
* server.close()
事件
* close 事件
* connect 事件
* request 事件
* finish 事件
配置
* server.maxHeadersCount
### 2.http.request
~~~
const postData = querystring.stringify({
'msg' : 'Hello World!'
});
const options = {
hostname: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = http.request(options, (res) => {
console.log(`狀態碼: ${res.statusCode}`);
console.log(`響應頭: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`響應主體: ${chunk}`);
});
res.on('end', () => {
console.log('響應中已無數據。');
});
});
req.on('error', (e) => {
console.error(`請求遇到問題: ${e.message}`);
});
// 寫入數據到請求主體
req.write(postData);
req.end();
~~~
### 3.http.get
~~~
http.get(url, (res) => {
console.log(res)
})
~~~
### 4. http中的類
http Agent 類
http ClientRequest 類
http Server類
http ServiceResponse類
http IncomingMessage 類
- Less
- 課程規劃
- Less概述
- 變量
- 混合
- 嵌套
- 繼承
- 導入
- 函數
- 其他
- 實戰
- ES6
- 課程規劃
- ES6概述
- let和const命令
- 變量的解構賦值
- 字符串擴展
- 函數擴展
- 數組擴展
- Set和Map數據結構
- Symbol
- Generator 函數
- Promise對象
- Class語法
- Module 的語法
- ES7和ES8
- 實戰
- VUE
- 課程規劃
- vue概述
- vue實例
- 模版語法
- 計算屬性和偵聽器
- Class和Style的綁定
- 條件渲染
- 列表渲染
- 事件處理
- 表單輸入綁定
- 組件基礎
- 過渡和動畫
- 自定義指令
- 過濾器
- 響應式原理
- 實戰課程
- Node
- 課程規劃
- 課程概述
- node入門實例
- 模塊系統
- 回調函數
- 全局對象
- 常用模塊介紹
- 常用模塊介紹-1
- 常用模塊介紹-2
- 常用模塊介紹-3
- npm使用
- express的使用
- express的使用-1
- webpack基礎
- 實戰
- 微信小程序
- 課程規劃
- 課程概述
- 基本配置和生命周期
- wxml模版
- wxss
- wxs
- 組件
- 微信API
- 自定義組件開發
- 實戰小程序
- Element
- 課程規劃
- 課程概述
- 特性介紹
- 組件介紹-基礎組件
- 組件介紹-表單組件
- 組件介紹-數據展示組件
- 組件介紹-提示組件
- 組件介紹-導航組件
- 組件介紹-其他組件
- 綜合案例