簡體   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