node.js - 我想从连续加载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'+'数据:{“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
你需要写一个解析器
推荐阅读
- python - 如何对包含单词列表的 DataFrame 行进行聚类?
- java - 在添加值的循环外部访问时,ArrayList 值更改为最后一个元素
- javascript - JSON解析以获取父名称
- git - 是否有任何可用的 CodeLens 附加组件显示给定方法的 git 历史记录?
- sql-server - 使用“0”参数调用“ExecuteNonQuery”的异常
- ios - 来自 Realm 的搜索数据阻塞了主线程
- java - 构建 Kie 会话线程安全吗?
- laravel - Laravel:在有多个急切加载查询时提高性能
- javascript - 如何深入比较两个 javascript 对象并返回所有差异,包括新添加的数组和相同的原始格式?
- angular - 使用翻译管道(ngx-translate),字符串被读取,但它仍然给出“无法读取属性”错误(Angular 6)