中文亂碼與locale有關,這裡給出兩種解決方法:
一、設定locale
1、setlocale(lc_all, "");//設定程式locale為系統預設(我的系統是zh_cn.utf8),gsoap內部進行編碼轉換依賴於locale,所以必須設定為中文環境。
2、gsoap初始化 gsoap生成的**類名字為:csmsproxy
csmsproxy soaprequest(soap_c_mbstring);
下面同一般程式設計。gsoap會自動把字串轉換為正確的編碼。
二、不設定locale,使用預設的"c" locale,程式中傳給gsoap、從gsoap接收的字串都使用utf8編碼
**類初始化: csmsproxy soaprequest(soap_c_utfstring);
下面同一般程式設計。gsoap會把字串當成utf8編碼處理。
下面附帶gb2312與utf8編碼之間的轉換函式:
//gb2312轉utf8
void gb2312toutf8(char* pstrout, u32 dwoutlen, const char* pstrin, u32 dwinlen)
widechartomultibyte(cp_utf8, 0, strsrc, -1, pstrout, i, null, null);
delete strsrc;
#else
iconv_t iconv = iconv_open("utf-8", "gb2312");
iconv(iconv, (char **)&pstrin, (size_t *)&dwinlen, (char **)&pstrout, (size_t *)&dwoutlen);
iconv_close(iconv);
#endif
}//utf8轉gb2312
void utf8togb2312(char* pstrout, u32 dwoutlen, const char* pstrin, u32 dwinlen)
#ifdef win32
int i = multibytetowidechar(cp_utf8, 0, pstrin, -1, null, 0);
wchar_t * strsrc = new wchar_t[i+1];
multibytetowidechar(cp_utf8, 0, pstrin, -1, strsrc, i);
i = widechartomultibyte(cp_acp, 0, strsrc, -1, null, 0, null, null);
if (i >= dwoutlen)
widechartomultibyte(cp_acp, 0, strsrc, -1, pstrout, i, null, null);
delete strsrc;
#else
iconv_t iconv = iconv_open("gb2312", "utf-8");
iconv(iconv, (char **)&pstrin, (size_t *)&dwinlen, (char **)&pstrout, (size_t *)&dwoutlen);
iconv_close(iconv);
#endif}
//gb2312轉unicode
void gb2312tounicode(wchar_t* pstrout, u32 dwoutlen, const char* pstrin, u32 dwinlen)
#ifdef win32
u32 i = multibytetowidechar(cp_acp, 0, pstrin, -1, null, 0);
if (i >= dwoutlen)
multibytetowidechar(cp_acp, 0, pstrin, -1, pstrout, i);
#else
iconv_t iconv = iconv_open("unicode", "gb2312");
iconv(iconv, (char**)pstrin, &dwinlen, (char**)pstrout, &dwoutlen);
iconv_close(iconv);
#endif
} //unicode轉gb2312
void unicodetogb2312(char* pstrout, u32 dwoutlen, const wchar_t* pstrin, u32 dwinlen)
#ifdef win32
u32 i = widechartomultibyte(cp_acp, 0, pstrin, -1, null, 0, null, null);
if (i >= dwoutlen)
widechartomultibyte(cp_acp, 0, pstrin, -1, pstrout, i, 0, 0);
#else
iconv_t iconv = iconv_open("gb2312", "unicode");
iconv(iconv, (char**)pstrin, &dwinlen, (char**)pstrout, &dwoutlen);
iconv_close(iconv);
#endif
} //utf8轉unicode
void utf8tounicode(wchar_t* pstrout, u32 dwoutlen, const char* pstrin, u32 dwinlen)
#ifdef win32
u32 i = multibytetowidechar(cp_utf8, 0, pstrin, -1, null, 0);
if (i >= dwoutlen)
multibytetowidechar(cp_utf8, 0, pstrin, -1, pstrout, i);
#else
iconv_t iconv = iconv_open("unicode", "utf-8");
iconv(iconv, (char**)pstrin, &dwinlen, (char**)pstrout, &dwoutlen);
iconv_close(iconv);
#endif }
gsoap 中文亂碼問題
中文亂碼與locale有關,這裡給出兩種解決方法 一 設定locale 1 setlocale lc all,設定程式locale為系統預設 我的系統是zh cn.utf8 gsoap內部進行編碼轉換依賴於locale,所以必須設定為中文環境。2 gsoap初始化 gsoap生成的 類名字為 csm...
解決gsoap中文亂碼的問題
在main函式裡初始化soap結構體後加入 這樣所有的c都是utf 8的格式,只要你的windows客戶端支援utf 8格式就沒有了亂碼問題 一般在ubuntu中都會預裝iconv的庫,使用也很簡單,網上的教程很多.下面的函式,在需要轉碼的地方呼叫即可 include ifdef iconv en ...
中文亂碼問題
母頁 tran cel.jsp?p user id p user id p paraxml mytran cel paraxml ie8對window.open二進位製流會遮蔽,用二次請求解決該問題 modify by 20120731。mytran cel paraxml encodeuri my...