node-- request对象和response对象

request 对象 和 response对象

request 对象

  • request 对象类型

response 对象

  • response 对象类型

// 示例代码:
res.writeHead(200, 'OK', {
  'Content-Type': 'text/html; charset=utf-8',
  'Content-Length': Buffer.byteLength(msg)
});
  • response.write(chunk[, encoding][, callback])

    • 参数1:要写入的数据,可以是字符串或二进制数据,必填
    • 参数2:编码,默认是utf8,选填。
    • 参数3:回调函数,选填。
  • response.end([data][, encoding][, callback])

    • 结束响应。
    • This method signals to the server that all of the response headers and body have been sent; that server should consider this message complete. The method, response.end(), MUST be called on each response.
    • res.end()这个方法告诉服务器所有要发送的响应头和响应体都发送完毕了。可以人为这次响应结束了。
    • 同时每次响应都必须调用该方法,用来结束响应

    • 参数1:结束响应前要发送的数据,选填。

    • 参数2:编码,选填。
    • 参数3:回调函数,选填。
  • response.setHeader(name, value)

    • 设置响应报文头
  • response.statusCode

    • 设置或读取http响应码
  • response.statusMessage

    • 设置或读取http响应状态消息
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值