express 邮件发送_使用Express发送回复

express 邮件发送

In the Hello World example we used the Response.send() method to send a simple string as a response, and to close the connection:

在Hello World示例中,我们使用Response.send()方法发送一个简单字符串作为响应,并关闭连接:

(req, res) => res.send('Hello World!')

If you pass in a string, it sets the Content-Type header to text/html.

如果传入字符串,它将Content-Type标头设置为text/html

if you pass in an object or an array, it sets the application/json Content-Type header, and parses that parameter into JSON.

如果传入对象或数组,它将设置application/json Content-Type标头,并将该参数解析为JSON

send() automatically sets the Content-Length HTTP response header.

send()自动设置Content-Length HTTP响应标头。

send() also automatically closes the connection.

send()也会自动关闭连接。

使用end()发送空响应 (Use end() to send an empty response)

An alternative way to send the response, without any body, it’s by using the Response.end() method:

没有任何内容的另一种发送响应的方法是使用Response.end()方法:

res.end()

设置HTTP响应状态 (Set the HTTP response status)

Use the Response.status():

使用Response.status()

res.status(404).end()

or

要么

res.status(404).send('File not found')

sendStatus() is a shortcut:

sendStatus()是一个快捷方式:

res.sendStatus(200)
// === res.status(200).send('OK')

res.sendStatus(403)
// === res.status(403).send('Forbidden')

res.sendStatus(404)
// === res.status(404).send('Not Found')

res.sendStatus(500)
// === res.status(500).send('Internal Server Error')

翻译自: https://flaviocopes.com/express-send-response/

express 邮件发送

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值