URLEnCode 编码 是怎么个情况

2025-06-23 05:48:00
推荐回答(1个)
回答1:

WCHAR* AnsiToUnicode(const char* buf)
{
int len = ::MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return L"";
::MultiByteToWideChar(CP_ACP, 0, buf, -1, wChar, len);
return wChar;
}

char* UnicodeToUtf8(const wchar_t* buf)
{
int len = ::WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return "";
::WideCharToMultiByte(CP_UTF8, 0, buf, -1, utf, len, NULL, NULL);
return utf;
}

CString URLEncode(CString sIn)
{
CString sOut;

const int nLen = sIn.GetLength() + 1;

register LPBYTE pOutTmp = NULL;
LPBYTE pOutBuf = NULL;
register LPBYTE pInTmp = NULL;
LPBYTE pInBuf =(LPBYTE)sIn.GetBuffer(nLen);
BYTE b = 0;

pOutBuf = (LPBYTE)sOut.GetBuffer(nLen*3 - 2);//new BYTE [nLen * 3];

if(pOutBuf)
{
pInTmp = pInBuf;
pOutTmp = pOutBuf;

while (*pInTmp)
{
char c = *pInTmp;
if (c<0||c>255)
{
*pOutTmp++ = '%';
*pOutTmp++ = toHex(*pInTmp>>4);
*pOutTmp++ = toHex(*pInTmp%16);
}

else if (isspace(*pInTmp))
{
*pOutTmp++ = '+';
}

else
{
*pOutTmp++ = *pInTmp;
}
pInTmp++;
}

*pOutTmp = '\0';
sOut.ReleaseBuffer();
}
sIn.ReleaseBuffer();
return sOut;
}

Cstring URL = http://112.90.87.3/dl.softmgr.qq.com/original/im/QQ1.99.8736.0.exe?
mkey=5338feeae7ee5787&f=3c13&p=.exe;
URL = UnicodeToUtf8(AnsiToUnicode(URL));
URL = URLEncode(URL);

URL 下载地址,有汉字也可以用