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

2,337次阅读

共计 628 个字符,预计需要花费 2 分钟才能阅读完成。

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)

正文完
 
Blood.Cold
版权声明:本站原创文章,由 Blood.Cold 2019-06-01发表,共计628字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。