Node.js:从不同文件发送XML响应

Node.js: Send XML response from different files

本文关键字:XML 响应 文件 js Node      更新时间:2023-09-26

有如下XML响应:

app.post '/incoming', (req,res) ->
    console.log "Hello, incoming call!"
    message = req.body.Body
    from = req.body.From
    sys.log "From: " + from + ", Message: " + message
    twiml = '<?xml version="1.0" encoding="UTF-8" ?>'n<Response>'n<Say>Thanks for your text, we''ll be in touch.</Say>'n</Response>'
    res.send twiml, {'Content-Type':'text/xml'}, 200

我可以有不同的。XML文件和res.send文件视情况而定?

当然;你用的是快递,对吗?使用res.sendfile:

app.post '/incoming', (req,res) ->
  console.log "Hello, incoming call!"
  message = req.body.Body
  from = req.body.From
  sys.log "From: " + from + ", Message: " + message
  if condition
    res.sendfile 'foo.xml'
  else
    res.sendfile 'bar.xml'