我正在尝试通过 HTTP 传输价格数据(不知道他们为什么不使用 websockets..)并且我使用 axios 发出正常的 REST API 请求,但我不知道如何处理“传输编码”:'分块”类型的请求。
此代码只是挂起并且不会产生任何错误,因此假设它正在工作但无法处理响应:
const { data } = await axios.get(`https://stream.example.com`, {headers:
{Authorization: `Bearer ${token}`, 'Content-Type': 'application/octet-
stream'}})
console.log(data) // execution hangs before reaching here
Run Code Online (Sandbox Code Playgroud)
感谢你的帮助。
工作解决方案:正如下面的答案所指出的,我们需要添加一个responseType:流作为axios选项,并在响应上添加一个事件监听器。
工作代码:
const response = await axios.get(`https://stream.example.com`, {
headers: {Authorization: `Bearer ${token}`},
responseType: 'stream'
});
const stream = response.data
stream.on('data', data => {
data = data.toString()
console.log(data)
})
Run Code Online (Sandbox Code Playgroud) 我正在尝试将本地 MongoDB 迁移到 Atlas。
我设法使用 localhost 运行 mongodump 命令,并且可以看到 ./dump/data.bson 中的文件
但是,当我现在想要将此转储恢复到 Atlas 时,我收到“失败:连接到数据库服务器时出错:没有可访问的服务器”。
这很奇怪,因为我可以使用以下命令从 mongo shell (v4.0) 连接到 Atlas:“mongo mongodb+srv://cluster0-xxxxxx.mongodb.net/test --username Bob”,其中提示我输入密码并连接良好。
这是 mongorestore 命令,它给了我上述连接错误:
mongorestore --ssl --host mongodb+srv://cluster0-xxxxx.mongodb.net/test --username Bob --authenticationDatabase admin --dir dump/data --password Test123
Run Code Online (Sandbox Code Playgroud)
感谢你的帮助。
我正在使用 Expo Google Fonts 和 useFonts() 方法为我的应用程序导入字体。但是我收到以下错误,但我认为我不需要将 Font.loadasync 与 Google Fonts 一起使用(根据此处的文档)。你能让我知道我在这里做错了什么吗?
import React, { useState } from "react";
import { View, TouchableOpacity, Text, StyleSheet, Platform } from 'react-native'
import { useFonts, Kanit_400Regular, Kanit_500Medium, Kanit_700Bold } from '@expo-google-fonts/kanit';
import Colors from '../constants/Colors'
const Header = props => {
useFonts({Kanit_400Regular, Kanit_500Medium, Kanit_700Bold})
return (
<View style={styles.headerContainer}>
<View style={styles.logo}>
<Text style={styles.headerText}>HEADER</Text>
</View>
<View>
<Text style={{...styles.headerText, fontSize: 14 }}>LOGIN</Text>
</View>
</View>
)
}
const styles = StyleSheet.create({
headerContainer: {
padding: 15, …
Run Code Online (Sandbox Code Playgroud) 数据库管理新手。我有一个书籍数据库,我想为 ISBN 创建一个长度为 13 个字符的索引。示例:'9781509825889'
目前我正在使用字符串索引,但我已经阅读了关于是否存储为 int 或字符串以进行索引优化的冲突点。
看起来我有 Int32 或 Int64 选项,我认为上面的 ISBN 对于 Int32 来说太大了,但是否值得切换到 Int64 进行查询优化,还是应该坚持使用字符串?是否有任何显着的性能提升?
谢谢
javascript ×2
mongodb ×2
axios ×1
database ×1
expo ×1
fonts ×1
http ×1
indexing ×1
node.js ×1
react-native ×1