找回密码
 加入
搜索
查看: 2272|回复: 4

[IE类操作] http响应是gbk编码,用binarytostring后有乱码!

[复制链接]
发表于 2015-1-2 22:00:14 | 显示全部楼层 |阅读模式
utf-8编码的http响应用binarytostring后显示正确,但gbk编码的http响应用binarytostring就有错码,几个参数都试过搞不懂,望高手指点
发表于 2015-1-2 22:28:55 | 显示全部楼层
不知道行不行[au3]//GBK编码转换到UTF8编码
int GBKToUTF8(unsigned char * lpGBKStr,unsigned char * lpUTF8Str,int nUTF8StrLen)
{
    wchar_t * lpUnicodeStr = NULL;
    int nRetLen = 0;

    if(!lpGBKStr)  //如果GBK字符串为NULL则出错退出
        return 0;

    nRetLen = ::MultiByteToWideChar(CP_ACP,0,(char *)lpGBKStr,-1,NULL,NULL);  //获取转换到Unicode编码后所需要的字符空间长度
    lpUnicodeStr = new WCHAR[nRetLen + 1];  //为Unicode字符串空间
    nRetLen = ::MultiByteToWideChar(CP_ACP,0,(char *)lpGBKStr,-1,lpUnicodeStr,nRetLen);  //转换到Unicode编码
    if(!nRetLen)  //转换失败则出错退出
        return 0;

    nRetLen = ::WideCharToMultiByte(CP_UTF8,0,lpUnicodeStr,-1,NULL,0,NULL,NULL);  //获取转换到UTF8编码后所需要的字符空间长度
   
    if(!lpUTF8Str)  //输出缓冲区为空则返回转换后需要的空间大小
    {
        if(lpUnicodeStr)
            delete []lpUnicodeStr;
        return nRetLen;
    }
   
    if(nUTF8StrLen < nRetLen)  //如果输出缓冲区长度不够则退出
    {
        if(lpUnicodeStr)
            delete []lpUnicodeStr;
        return 0;
    }

    nRetLen = ::WideCharToMultiByte(CP_UTF8,0,lpUnicodeStr,-1,(char *)lpUTF8Str,nUTF8StrLen,NULL,NULL);  //转换到UTF8编码
   
    if(lpUnicodeStr)
        delete []lpUnicodeStr;
   
    return nRetLen;
}[/au3]
 楼主| 发表于 2015-1-2 23:05:13 | 显示全部楼层
binarytostring 没有GBK这个选项。这应该是乱码的原因。满世界没找到办法?楼上提供的代码不知道在autoit中咋用?
发表于 2015-1-2 23:10:35 | 显示全部楼层
_winapi_MultiByteToWideChar
_winapi_WideCharToMultiByte说白了,就是这两个函数
发表于 2015-1-22 20:44:48 | 显示全部楼层
你给个gbk编码的网页
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 12:12 , Processed in 0.070722 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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