提问者:小点点

我想从一个不断加载节点的链接中检索数据


我无法从节点js中链接检索数据。


共1个答案

匿名用户

您只需发出http请求:

var http = require('https')


var options = {
  host: 'konnectprodstream3.knowlarity.com',
  port: 8200,
  path: '/update-stream/02a53c9aec84/konnect',
  method: 'GET'
}

const req = http.request(options, (response) => {
  response.on('data', function (chunk) {
    console.log({ chunk: chunk.toString() })
  })

  response.on('end', function () {
    console.log('End')
  })
})

req.end()

它将打印:

{chunk:'id:20\n'+'数据:{“event_type”:“customer_answer”,“business_call_type”:“出站”,“agent_number”:“+919911782019”,“call_recording”:NULL,“knowlarity_number”:“+919311583261”,“uuid”:“10e5bf5d-8e9f-465d-8920-3d0995210aae”,“call_direction”:“出站”,“caller”:“+919899625014”,“customer_number”:“

因为服务器已发送事件的格式为:

id: 20\n
data: <json>\n
\n # end of the message

您需要编写一个解析器