【问题标题】:Node.js: Send XML response from different filesNode.js:从不同的文件发送 XML 响应
【发布时间】:2011-09-05 11:01:18
【问题描述】:

有这样的 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 文件吗?

【问题讨论】:

    标签: javascript xml node.js coffeescript


    【解决方案1】:

    当然;你用的是快递,对吧?使用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'
    

    【讨论】:

      猜你喜欢
      • 2012-04-20
      • 2013-10-23
      • 2016-06-14
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多