- href 被转换的原URL字符串
 - protocal 客户端发出请求时使用的协议
 - slashes 在协议与路径之间是否使用了//分隔符
 - host URL字符串中的完整地址和端口号
 - auth URL字符串中的认证部分
 - hostname URL字符串中的完整地址
 - port URL字符串中的端口号
 - pathname URL字符串的路径,不包含查询字符串
 - search 查询字符串,包含?
 - path 路径,包含查询字符串
 - query 查询字符串,不包含起始字符串?
 - hash 散列字符串,包含#
 
发送服务器响应流
http.ServerResponse对象表示响应对象
header
设置、获取和删除Header
response.setHeader('Content-Type','text/html;charset=utf-8');response.getHeader('Content-Type');response.removeHeader('Content-Type');response.headersSent 判断响应头是否已经发送
headersSent
判断响应头是否已经发送
const http = require('http');const server = http.createServer(function(req,res){console.log(resopnse.headersSent ? "响应头已经发送" : "响应头未发送!");res.writeHead(200,'ok);console.log(resopnse.headersSent ? "响应头已经发送" : "响应头未发送!");});
response
response.writeHead(statusCode,[reasonPhrase],[headers]);
writeHead
content-type 内容类型
location 将客户端重定向到另外一个URL地址
content-disposition 指定一个被下载的文件名
content-length 服务器响应内容的字节数
set-cookie 在客户端创建Cookie
content-encoding 指定服务器响应内容的编码方式
cache-cache 开启缓存机制
expires 用于制定缓存过期时间
etag 指定当服务器响应内容没有变化不重新下载数据
http客户端
向其他网站请求数据
let req = http.request(options,callback);req.on('request',callback);request.write(chunk,[encoding]);request.end([chunk],[encoding]);
- host 指定目标域名或主机名
 - hostname 指定目标域名或主机名,如果和host都指定了,优先使用hostname
 - port 指定目标服务器的端口号
 - localAddress 本地接口
 - socketPath 指定Unix域端口
 - method 指定HTTP请求的方式
 - path 指定请求路径和查询字符串
 - headers 指定客户端请求头对象
 - auth 指定认证部分
 - agent 用于指定HTTP代理,在Node.js中,使用http.Agent类代表一个HTTP代理,默认使用keep-alive连接,同时使用http.Agent对象来实现所有的HTTP客户端请求
 
