小编Cla*_*eld的帖子

NodeJs Axios 响应错误编码

我正在尝试使用 Axios 调用 REST 调用并得到奇怪的响应。

\n
try {\n  \n   const response = await axios.get("https://api.predic8.de/shop/products/");\n   console.log(response.data);\n}\ncatch (error) {\n    console.log(`[Error] -> ${JSON.stringify(error.response.data)}`)\n}\n
Run Code Online (Sandbox Code Playgroud)\n

其结果如下:

\n

\xe2\x96\xbc\xe2\x99\xa5\xef\xbf\xbd\xef\xbf\xbdM\n\xef\xbf\xbd0\n5\xef\xbf\xbdZ\xef\xbf\xbdz\xef\xbf \xbdwg\xef\xbf\xbd4\xd3\x8e\xef\xbf\xbdW\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdYjxt\xca \xb8\xef\xbf\xbd\xef\xbf\xbd:\xef\xbf\xbd\xc7\x8f\xe2\x96\xba_\xef\xbf\xbd\xe2\x98\xba}Y\xef\xbf\ xbd\xef\xbf\xbd/\xef\xbf\xbdR2~\xe2\x99\xa0$\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdU\xcc\x81\xef\xbf\xbdV \xef\xbf\xbd8\\\xef\xbf\xbd]!\xef\xbf\xbd )\xe2\x98\xba*\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdH\xef\xbf\xbd\xef\xbf\xbd>\xef\xbf\xbd\xc2\xa7\xef\xbf\xbd\xef\xbf\xbdAj"\xe2\x86\x95\xef\xbf\xbd\xef\xbf\xbda0 \xdd\x9a\xef\xbf\xbd\xef\xbf\xbd$\xef\xbf\xbd\xe9\xa2\xb2Y3%je3@=\xef\xbf\xbd0\xef\xbf\xbd\xef\xbf\xbd@\xc2\xa7lb:\xef\xbf\xbd|\xef\xbf\xbd} .\xe2\x98\xba8\xef\xbf\xbdK&\xef\xbf\xbd_\xc6\xabp\xef\xbf\ xbdj\xef\xbf\xbd(o-\xef\xbf\xbd\xdc\x9a\xe2\x99\xa6

\n

我需要做什么才能获取 json 对象?

\n

我尝试添加带有编码和内容类型的标头标头,但没有成功。

\n

javascript node.js axios

5
推荐指数
1
解决办法
2082
查看次数

标签 统计

axios ×1

javascript ×1

node.js ×1