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



我无法从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'+'数据:{"事件类型":"CUSTOMER_ANSWER","business_call_type":"出站","代理编号":"+91911782019","呼叫记录":空,"已知编号"::"+99131583621","uuid":"10e5bf5d-8e9f-465d-8920-3d099"5210aae","call_direction":"Outbound","呼叫者":"+91899625014"现状t、 "customer_number":"919899625014"版本":"1.0〃"k_number":"919311583261〃"类型":"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-3d0995210ae_0"variable_current_application":"record_session"事件日期本地":"2020-08-13 18:12:21"variable_sip_call_id":"40404c79-5805-1239-a8b10-002590a61e05"Caller_Channel_Created_Time":"1597322532425716"Caller_Channel_Progress_Media_Time":"1597322533585716"}\n’+'\n'}

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

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

您需要编写一个解析器

最新更新