http請(qǐng)求:
option 數(shù)組對(duì)象,包含以下參數(shù):
host: 表示請(qǐng)求網(wǎng)站的域名或IP地址(請(qǐng)求的地址)。 默認(rèn)為'localhost'。
hostname: 服務(wù)器名稱(chēng),主機(jī)名是首選的值。
port: 請(qǐng)求網(wǎng)站的端口,默認(rèn)為 80。
localAddress: 建立網(wǎng)絡(luò)連接的本地
socketPath: Unix Domain Socket(Domain套接字路徑)
method: HTTP請(qǐng)求方法,默認(rèn)是 ‘GET'。
path: 請(qǐng)求的相對(duì)于根的路徑,默認(rèn)是'/'。QueryString應(yīng)該包含在其中。例如:/index.html?page=12
headers: 請(qǐng)求頭對(duì)象。
auth: Basic認(rèn)證(基本身份驗(yàn)證),這個(gè)值將被計(jì)算成請(qǐng)求頭中的 Authorization 部分。
callback : 回調(diào),傳遞一個(gè)參數(shù),為 http.ClientResponse的實(shí)例。http.request 返回一個(gè) http.ClientRequest 的實(shí)例。
headers:
{ host: '192.168.127.132:1337',//主機(jī)地址
connection: 'keep-alive',//長(zhǎng)鏈接
'cache-control': 'max-age=0',//控制緩存
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',//請(qǐng)求頭 類(lèi)型
'upgrade-insecure-requests': '1',//自動(dòng)升級(jí)請(qǐng)求https
'user-agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36',//用戶(hù)系統(tǒng)信息
'accept-encoding': 'gzip, deflate, sdch',//編碼類(lèi)型
'accept-language': 'zh-CN,zh;q=0.8' },//編碼語(yǔ)言
ServerResponse
ServerResponse {
domain: null,//域
_events: [Object],//事件集
_eventsCount: 1,//事件計(jì)數(shù)
_maxListeners: undefined,//最大監(jiān)聽(tīng)數(shù)
output: [],//響應(yīng)流文本輸出
outputEncodings: [],//編碼
outputCallbacks: [],//回調(diào)
outputSize: 0,//大小
writable: true,//可寫(xiě)
_last: false,//
chunkedEncoding: true,//
shouldKeepAlive: true,//是否保持連接
useChunkedEncodingByDefault: true,//
sendDate: true,//
_removedHeader: {},//
_contentLength: null,//內(nèi)容長(zhǎng)度
_hasBody: true,//
_trailer: '',//
finished: false,//
_headerSent: false,//
socket: [Circular],//
connection: [Circular],//
_header: 'HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nDate: Tue, 09 Aug 2016 02:24:03 GMT\r\nConnection: keep-alive\r\nTransfer-Encoding: chunked\r\n\r\n',//報(bào)頭
_headers: null,//
_headerNames: {},//
_onPendingData: [Function: updateOutgoingData],//
statusMessage: 'OK',//
statusCode: 200 } },//