|
[code]https://github.com/JelinYao/HttpInterface
[/code]
获得的字符串 再AsCString即可。
std::wstring ANSI2unicode(const char *psz, const DWORD &codePage)
{
if (!psz) return std::wstring(L"");
int nLength, nLen;
wchar_t *pBuffer;
nLen = (int)strlen(psz);
nLength = ::MultiByteToWideChar(codePage, 0, psz, nLen, NULL, 0);
pBuffer = new wchar_t[nLength + 1];
memset(pBuffer, 0, (nLength + 1)*sizeof(wchar_t));
::MultiByteToWideChar(codePage, 0, psz, nLen, (LPWSTR)pBuffer, nLength);
std::wstring wstr(pBuffer);
delete[] pBuffer;
return wstr;
}
std::string unicode2ANSI(const wchar_t *psz, const DWORD &codePage)
{
if (!psz) return std::string("");
char *pBuffer;
int nLength;
int nLen;
nLen = (int)wcslen(psz);
nLength = ::WideCharToMultiByte(codePage, 0, psz, nLen, NULL, 0, 0, 0);
int rc = ::GetLastError();
pBuffer = new char[nLength + 1];
memset(pBuffer, 0, (nLength + 1)*sizeof(char));
::WideCharToMultiByte(codePage, 0, psz, nLen, pBuffer, nLength, 0, 0);
std::string str(pBuffer);
delete[] pBuffer;
return str;
}
CString AsCString(const char *str)
{
std::wstring wstr;
if (NULL != str)
wstr = ANSI2unicode(str, CP_UTF8);
return wstr.c_str();
}
CString AsCString(std::string str)
{
return AsCString(str.c_str());
}
std::string AsString(const wchar_t *pszStr)
{
std::string str;
if (NULL != pszStr)
str = unicode2ANSI(pszStr, CP_UTF8);
return str;
}
主要实现了HTTP的get\post方法,下载到内存、下载到本地文件,回调下载进度等接口 测试程序中展现了常用的几个方法。 |
|