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')
express 邮件发送