我所要做的就是更改php.ini文件中的默认字符集
default_charset = "UTF-8"
<击> 我正在尝试用PHP创建一个SOAP客户端,但我遇到了编码问题。 $ Response包含不正确字符的单词,例如è。而不是è。
将WSDL文件导入instructions(soap测试套件)时,响应会被正确编码,因此我认为它与SOAP服务无关。 SoapUI表明它使用的是UTF-8。我也试过了一堆其他SoapUI,但没有成功。
我所有的php文件都是用UTF-8编码的。
$client = new SoapClient($wsdl_file, array('encoding'=>'UTF-8'));
$Response = $client->__soapCall('GetMemberDetails', array($request));
debug($Response); die;
样本回复:
<members xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserInfo>
...
<Status>règle</Status>
...
</UserInfo>
</members>
这是来自SoapUI的原始请求
POST http://test.app.com/WebServices/MemberService/MemberService.svc HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://test.org/MemberService/GetMemberDetails"
Content-Length: 419
Host: test.app.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
有没有办法在PHP中从SoapClient获取相同类型的原始请求?
编辑:我在__doRequest中拦截了请求。以下是SoapClient和SoapUI之间的区别
SoapClient(接收编码错误)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test.org/">
<SOAP-ENV:Body>
<ns1:GetMemberDetails>
<ns1:memberId>123</ns1:memberId>
</ns1:GetMemberDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SoapUI(接收正确的编码)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://test.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GetMemberDetails>
<!--Optional:-->
<tem:memberId>123</tem:memberId>
</tem:GetMemberDetails>
</soapenv:Body>
</soapenv:Envelope>
击> <击> 撞击>
答案 0 :(得分:0)
确保正确配置php charset
在你的php.ini文件中
default_charset = "UTF-8"