php - php编码:违反编码规则
问题描述
我有一个 PHP 脚本正在向服务器发出 SOAP 请求。PHP 错误
SOAP-ERROR: Encoding: Violation of encoding rules
最初的直觉是我的请求有问题。我对请求进行了网络捕获,并通过 curl 将其发送到 Web 服务器,它似乎恢复正常。PHP soap 和 curl 发送的请求是相同的,即:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com/Integrics/Enswitch/API" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:download_music_file><username xsi:type="xsd:string">dovid</username><password xsi:type="xsd:string">passsowrd</password><music xsi:type="xsd:int">45</music><file xsi:type="xsd:int">1</file><checking xsi:type="xsd:int">0</checking></ns1:download_music_file></SOAP-ENV:Body></SOAP-ENV:Envelope>
回应是:
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><download_music_fileResponse xmlns="http://www.example.com/Integrics/Enswitch/API"><gensym><name xsi:type="xsd:string">music_45_1.wav</name><data xsi:type="xsd:base64Binary">BASE 64 REMOVED</data><mimetype xsi:type="xsd:string">audio/x-wav</mimetype></gensym></download_music_fileResponse></soap:Body></soap:Envelope>
执行该任务的 php 代码是:
<?PHP
ini_set("soap.wsdl_cache_enabled", "0");
$uid = 'dovid';
$pass = 'password';
$func = 'download_music_file';
$soap = new SoapClient("enswitch_3.9.wsdl", array('trace' => true, 'exceptions' => false, 'keep_alive' => false, 'connection_timeout' => 15));
$result1 = $soap->$func($uid, $pass, 45, 1,0);
if(isset($soap->__soap_fault)){
echo 'There was an error connecting via SOAP. Below is the error:';
print_r($soap->__soap_fault->faultstring);
}
?>
解决方案
推荐阅读
- wpf - 为什么 DataTrigger 设置 DataGridColunm 的标题不起作用?
- performance - 如何有效地加载 ArrayCollection 中的最后一项?
- ansible - 使用 ansible 动态添加子组
- highcharts - 条形图在时间线中创建间隙
- qt - 如何使用 Qt 应用程序安装和卸载 Win 服务
- java - Spring获取没有注释的entityManger
- jquery - Boostrap 下拉菜单在悬停时关闭
- angularjs - IE11 在 AngularJS 应用程序中用 NTLM 替换 Bearer
- c# - 在 Cmake C# 项目中使用 DLL
- laravel-5 - laravel 5.8 - 创建和更新用户的个人资料