吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1432|回复: 2
收起左侧

[求助] NodeJS GBK转码UTF-8问题

[复制链接]
_知鱼之乐 发表于 2021-5-18 14:53
本帖最后由 _知鱼之乐 于 2021-5-18 14:57 编辑

一、
这是通过谷歌调试工具中看到的相应内容
[Asm] 纯文本查看 复制代码
<?xml version="1.0" encoding="gbk"?><ajax><![CDATA[非法请求,请返回重试!]]></ajax>

image.png

二、
当用node fetch请求获取结果时   乱码状态
<?xml version="1.0" encoding="gbk"?><ajax><![CDATA[&#65533;&#503;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#48629;&#65533;&#65533;&#65533;&#65533;&#65533;&#1315;&#65533;]]></ajax>
image.png

三、
尝试网上的方式转码  gb2312 和 gbk 都不能转化
[Asm] 纯文本查看 复制代码
 let a = Buffer.from(d)
                var html = iconv.decode(a, 'gb2312');
                console.log("&#128640; ~ data.text ~ html", html, 'end')

image.png



请问如何把第二步的转码成UTF-8

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

fanvalen 发表于 2021-5-18 16:46


欧美的编码

    ASCII码
    ISO-8859-1编码

中文系列编码

    GB2312编码
    GBK编码
    BIG5编码
    GB18030编码
    ANSI 编码

Unicode与UCS
Unicode标准

Unicode编码的不同实现

    UTF-8编码
    UTF-16编码
    UTF-32编码
安保这些编码都试试
 楼主| _知鱼之乐 发表于 2021-6-10 15:32
[JavaScript] 纯文本查看 复制代码
    let url = "http://whois.pconline.com.cn/ipJson.jsp";
    fetch(url, {
        method: 'GET',
        // body: null,    
        redirect: 'follow', // set to `manual` to extract redirect headers, `error` to reject redirect 
        timeout: 10000,      //ms 
    }).then(function (res) {
        console.log("Response Headers ============ ");
        res.headers.forEach(function (v, i, a) {
            console.log(i + " : " + v);
            if (i.toLowerCase() == "content-type") charset = v.split("charset=").reverse()[0];
        });
        return res.buffer();
    }).then(function (res) {
        console.log("Response Body ============ ");
        let body = iconv.decode(Buffer.concat([res]), 'GBK');
        console.log("&#128640; ~ GetIP ~ body", body)
    });


上面代码可以转,无意之间找到
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-10 01:00

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表