关于UNICODE转化成UTF8和POST
2009-02-12 17:34
155 查看
为这点小事也能郁闷。。
注意参数:
WideCharToMultiByte(CP_UTF8, 0, pszValue, -1, buf, 255, NULL, NULL );
BOOL result = FALSE;
CInternetSession session;
CHttpFile* pFile;
CHttpConnection* pConnection;
try
{
char strUtf8Req[512];
memset( strUtf8Req, 0, 512);
WCHAR* strWchar;
strWchar = request.GetBuffer();
string str;
GetAnsiString( str, strWchar);
strcpy( strUtf8Req, str.c_str() );
CString strServerName = _T("a.b.c.d:8080");
CString strFormAction = _T("/xx/api/xxxxx");
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded");
pConnection = session.GetHttpConnection(strServerName);
if( pConnection == NULL)
return FALSE;
pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, strFormAction);
if( pFile == NULL)
return FALSE;
//result = pFile->SendRequest( strHeaders, (void*)strFormData, strlen(strFormData) );
result = pFile->SendRequest( strHeaders, (void*)strUtf8Req, strlen(strUtf8Req) );
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
if( dwRet == HTTP_STATUS_OK)
{
CString responseUtf8;
CString strLine;
while(pFile->ReadString(strLine))
{
responseUtf8 += strLine;
}
char* strUtf8 = (char*)responseUtf8.GetBuffer();
result = ParseResponse(strUtf8, response);
responseUtf8.ReleaseBuffer();
}
pFile->Close();
session.Close();
pConnection->Close();
}
catch (CInternetException* e)
{
pFile->Close();
session.Close();
pConnection->Close();
CString s;
s.Format(_T("Internet Exception/r/nm_dwError%u,m_dwContextError%u"),e->m_dwError,e->m_dwContext);
AfxMessageBox(s);
return FALSE;
}
return result;
注意参数:
WideCharToMultiByte(CP_UTF8, 0, pszValue, -1, buf, 255, NULL, NULL );
BOOL result = FALSE;
CInternetSession session;
CHttpFile* pFile;
CHttpConnection* pConnection;
try
{
char strUtf8Req[512];
memset( strUtf8Req, 0, 512);
WCHAR* strWchar;
strWchar = request.GetBuffer();
string str;
GetAnsiString( str, strWchar);
strcpy( strUtf8Req, str.c_str() );
CString strServerName = _T("a.b.c.d:8080");
CString strFormAction = _T("/xx/api/xxxxx");
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded");
pConnection = session.GetHttpConnection(strServerName);
if( pConnection == NULL)
return FALSE;
pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, strFormAction);
if( pFile == NULL)
return FALSE;
//result = pFile->SendRequest( strHeaders, (void*)strFormData, strlen(strFormData) );
result = pFile->SendRequest( strHeaders, (void*)strUtf8Req, strlen(strUtf8Req) );
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
if( dwRet == HTTP_STATUS_OK)
{
CString responseUtf8;
CString strLine;
while(pFile->ReadString(strLine))
{
responseUtf8 += strLine;
}
char* strUtf8 = (char*)responseUtf8.GetBuffer();
result = ParseResponse(strUtf8, response);
responseUtf8.ReleaseBuffer();
}
pFile->Close();
session.Close();
pConnection->Close();
}
catch (CInternetException* e)
{
pFile->Close();
session.Close();
pConnection->Close();
CString s;
s.Format(_T("Internet Exception/r/nm_dwError%u,m_dwContextError%u"),e->m_dwError,e->m_dwContext);
AfxMessageBox(s);
return FALSE;
}
return result;
相关文章推荐
- 关于unicode,mbcs,utf8,charset,encoding等相关概念的说明....Zzz
- C++中ASCII、unicode与Utf8之间的相互转化
- 关于unicode,mbcs,utf8,charset,encoding等相关概念的说明
- 关于unicode、utf8、utf16、gb2312和GBK的一些理解
- 关于unicode、utf8、utf16、gb2312和GBK的一些理解
- 关于unicode,mbcs,utf8,charset,encoding等相关概念的说明
- 转载 ANSI、Unicode、UTF8相互转化的函数
- mysql关于utf8_unicode_ci与utf8mb4_unicode_ci的区别
- ANSI、Unicode、UTF8相互转化的函数
- Unicode与UTF8相互转化(使用MultiByteToWideChar)
- 关于utf8 unicode gbk 编码乱码汇总
- ASCII-->Ansi-->Unicode-->UTF8 关于编码 自己的总结
- UTF8是将Unicode的规定转化为比较省字节的一种存储和传送方式
- 关于编码: ascii(ansi), gb-2312, unicode, utf8
- utf8编码转化为unicode的一个精彩函数
- 关于unicode,mbcs,utf8,charset,encoding等相关概念的说明
- 关于字符编码精简介绍 ANSI GB2312 UTF8 UNICODE
- 关于unicode,mbcs,utf8,charset,encoding等相关概念的说明
- C++中ASCII、unicode与Utf8之间的相互转化
- C/C++ 各种字符编码字符串的转换 可用于XML文件的字符转化读写 (收集 GBK - UTF8 - Unicode - ANSI )