在gsoap中处理编码问题

来源:互联网 发布:这些网络舆情的办理 编辑:程序博客网 时间:2024/06/08 06:48

            在gsoap中,如果遇到编码问题,首先利用下面这个函数设置gsoap的接收的编码格式。如下例,把gsoap编码设置为UTF-8的格式:

            soap_set_mode(p_IASServer->soap, SOAP_C_UTFSTRING); 

            因此,您只需要把编码转换为UTF-8后传递给gsoap即可。

            例如 ANSI 与 UTF-8的互转

char*  ANSI2UTF8(char* szSource, bool bPositive)     // bPositive: 1 ansi to utf-8 , 1: utf-8 to ansi{  char* pszWideData, *pszReturn; int   nlen = 0; int   nFirstType = CP_ACP; int   nSecondType = CP_UTF8; if( !bPositive ) {  nFirstType = CP_UTF8;  nSecondType = CP_ACP; } if( !szSource || (strlen(szSource) == 0)) {  return NULL; } nlen = MultiByteToWideChar(nFirstType, 0, szSource, -1, NULL, 0); pszWideData = new char [nlen * 2]; MultiByteToWideChar(nFirstType, 0, szSource, -1, (LPWSTR)pszWideData, nlen);

 nlen = WideCharToMultiByte(nSecondType, 0, (LPCWSTR)pszWideData, nlen, NULL, 0, NULL, FALSE); pszReturn = new char[nlen]; WideCharToMultiByte(nSecondType, 0, (LPCWSTR)pszWideData, nlen, pszReturn, nlen, NULL, FALSE);

 delete [] pszWideData; return pszReturn;}

           不过由于对GSoap还不是很熟悉,所以不知如何获取服务端返回的信息(以附件形式传送),有待进一步学习!!

原创粉丝点击