0%

JS axios 使用 eventstream

用 Axios 获取 EventStream

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const response = await axios.get('https://stream.example.com', {
headers: {Authorization: `Bearer ${token}`,
responseType: 'stream'
});

const stream = response.data;

stream.on('data', data => {
console.log(data);
});

stream.on('end', () => {
console.log("stream done");
});