首页 > 解决方案 > 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);
    }
?>

标签: phpsoap

解决方案


推荐阅读