繁体   English   中英

Node.js:从其他文件发送XML响应

[英]Node.js: Send XML response from different files

具有以下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他们根据条件?

当然; 您正在使用Express,对吗? 使用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'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM