首页 > 解决方案 > 我想从连续加载nodejs的链接中检索数据

问题描述

我无法从 Node js 中的该链接检索数据。

标签: node.js

解决方案


你只需要发出一个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()

它将打印:

{块:'id:20\n'+'数据:{“event_type”:“CUSTOMER_ANSWER”,“business_call_type”:“Outbound”,“agent_number”:“+919911782019”,“call_recording”:null,“knowlarity_number”: "+919311583261","uuid":"10e5bf5d-8e9f-465d-8920-3d0995210aae","call_direction":"Outbound","caller":"+919899625014","customer_number":"+919899625014","version" :"1.0","k_number":"+919311583261","type":"CUSTOMER_ANSWER","unique_id":"f019cd36-37fb-43ab-afe3-0667c75584b1","call_solution":"c2c","FreeSWITCH_IPv4": "10.0.0.10","Other_Leg_Unique_ID":"10e5bf5d-8e9f-465d-8920-3d0995210aae_0","variable_current_application":"record_session","Event_Date_Local":"2020-08-13 18:12:21","variable_sip_call_id":"40404c79-5805-1239-a16b1-00259a ","Caller_Channel_Created_Time":"1597322532425716","Caller_Channel_Progress_Media_Time":"1597322533585716"}\n' + '\n' }

由于服务器发送事件的格式是:

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

你需要写一个解析器


推荐阅读