Table Of Contents

骑驴找蚂蚁

全干工程师

php调用gSoap服务时出现中文乱码问解决方法

gSoap一种跨平台的C和 C++软件开发工具包。生成C/C++的RPC代码,XML数据绑定,对SOAP Web服务和其他应用形成高效的具体架构解析器,它们都受益于一个XML接口。

gSoap生成的服务默认是以ASCII编码作为字符串, 而导致多字节的中文客户接收是乱码,官方文档有一句可以描述

Strings with 8-bit content can hold ASCII (default) or UTF8. The latter is possible by enabling the SOAP_C_UTFSTRING flag. When enabled, all std::string and char* strings MUST contain UTF8.

gSOAP provides flags to control the input and output mode settings at runtime. These flags are divided into four categories: transport (IO), content encoding (ENC), XML marshalling (XML), and C/C++ data mapping (C).

通过上面的描述我们可以得知,我们只要设置运行时的模式为SOAP_C_UTFSTRING 标识就行了.

struct soap soap; 
soap_init1(&soap, SOAP_C_UTFSTRING);
//或者
soap_set_mode(&soap, SOAP_C_UTFSTRING)

 

留言