【问题标题】:Bad html encoding when request axios in nodejs在nodejs中请求axios时错误的html编码
【发布时间】:2022-12-19 18:22:01
【问题描述】:

我在使用 axios get 请求时遇到了同样的问题。我期待真正的 html 代码,但得到错误的编码字符集。请帮忙!

附言附上 axios 输出的屏幕截图,而不是页面的 html 代码enter image description here

我只是向页面发送请求,而不是 html 代码,我得到了一些乱码

【问题讨论】:

  • 如果您使用的是 axios 1.2.0,这可能是因为this issue

标签: node.js axios


【解决方案1】:

在 v1.2.1 中,修复了这个错误。

在Axios Get API的header中添加Accept-Encodingtext/html; charset=UTF-8

axios.get("your URL",{ headers: { 'Accept-Encoding': 'text/html; charset=UTF-8',}}).then(response => console.log(response.data))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-06
    • 1970-01-01
    • 2020-09-24
    • 2018-03-01
    • 2019-01-06
    • 2017-03-23
    相关资源
    最近更新 更多