VC++(unicode)实现URLDecode函数,对URl编码的字符串进行解码
来源:互联网 发布:杨氏模量测量实验数据 编辑:程序博客网 时间:2024/05/16 05:39
JAVA中使用Urlencode.encoder,
但是用vc++开发过程中,需要对URL编码的字符串进行编码,也就是URLDecode函数,此代码是从网上找到的,但是对url编码字符串解码结果不太正常,稍加了一点改动,可以正常对url编码字符串解码。代码如下:
#define IsHexNum(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
//urf8编码字符串处理
CString Utf8ToStringT(LPSTR str)
{
_ASSERT(str);
USES_CONVERSION;
WCHAR *buf;
int length = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
buf = new WCHAR[length+1];
ZeroMemory(buf, (length+1) * sizeof(WCHAR));
MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, length);
return (CString(W2T(buf)));
}
CString UrlDecode(LPCTSTR url)
{
_ASSERT(url);
USES_CONVERSION;
LPSTR _url = T2A(const_cast<LPTSTR>(url));
int i = 0;
int length = (int)strlen(_url);
CHAR *buf = new CHAR[length];
ZeroMemory(buf, length);
LPSTR p = buf;
char tmp[4];
while(i < length)
{
if(i <= length -3 && _url[i] == '%' && IsHexNum(_url[i+1]) && IsHexNum(_url[i+2]))
{
memset(tmp, 0, sizeof(tmp));
memcpy(tmp, _url + i + 1,2);
sscanf(tmp, "%x", p++);
i += 3;
}
else
{
*(p++) = _url[i++];
}
}
//return CString(buf);
return Utf8ToStringT(buf);
}
//进行Url编码 UTF - 8
CString UrlEncode(CString strUnicode)
{
LPCWSTR unicode = T2CW(strUnicode);
int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, 0, 0, 0, 0);
if (!len)
return strUnicode;
char *utf8 = new char[len + 1];
char *utf8temp = utf8;
WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0);
utf8[len] = NULL;
CString strTemp, strEncodeData;
while (*utf8!= '\0')
{
strTemp.Format(_T("%%%2x"), (BYTE)*utf8);
strEncodeData += strTemp;
++utf8;
}
delete[]utf8temp;
return CString(strEncodeData);
}
- VC++(unicode)实现URLDecode函数,对URl编码的字符串进行解码
- JS对URL字符串进行编码/解码
- Qt进行UrlEncode/UrlDecode(URL编码/解码)
- Qt进行UrlEncode/UrlDecode(URL编码/解码)
- iOS开发中Objective-C 对 URL的URLEncode(编码)与URLDecode(解码)
- iOS开发中Objective-C 对 URL的URLEncode(编码)与URLDecode(解码)
- JS对URL字符串进行编码/解码分析
- JS对URL字符串进行编码/解码分析
- JS对URL字符串进行编码/解码分析
- JS对URL字符串进行编码/解码分析
- JS对URL字符串进行编码/解码分析
- PHP中对汉字进行UNICODE编码和解码的实现
- PHP中对汉字进行UNICODE编码和解码的实现
- PHP中对汉字进行UNICODE编码和解码的实现
- PHP中对汉字进行unicode编码和解码的实现
- 对字符串进行编码解码
- URL字符串解析(UrlDecode vc)
- URL字符串解析(UrlDecode vc)
- 大话设计模式读后感之装饰模式
- 高可用、开源的Redis缓存集群方案
- c++ unique_lock与lock_guard的区别
- [USACO3.2]纺车的轮子 Spinning Wheels
- System.IO.Directory.GetCurrentDirectory与System.Windows.Forms.Application.StartupPath的用法
- VC++(unicode)实现URLDecode函数,对URl编码的字符串进行解码
- Cache 的作用
- 7.IDA-创建结构体
- 基于AWS搭载laravel
- 常见开源协议简介
- git ignore~
- 微信小程序入门——增删改查+页面跳转+传值取值+布局样式
- 视频会议十大开源项目排行
- VBS中连接Mysql数据库方法