我在设置 SOAP header 时遇到两个问题。首先,我以前从未这样做过,其次,我似乎无法在这里找到一个好的解决方案。如果有完全相同的重复项,我深表歉意,如果有,请指出正确的方向。
我需要在soap:Envelope 上设置以下xmlns:xsi 和xmlns:xsd 数据集。我还需要在 XML 中的第一个标签上设置 xmlns 属性(粗略示例)。
需要添加第一部分,当我执行 __getLastRequest() 时,第二部分已经在那里。需要添加第三部分(仅 SendPurchases xmlns 属性)。
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
xmlns:ns1="urn:[taken out for security purposes]">
<soap:Body>
<SendPurchases xmlns="urn:...">
</SendPurchases>
</soap:Body>
我需要为此使用 header() 吗? 我正在使用 PHP 的 SOAP 客户端。非常感谢任何帮助!
编辑:
我选择了另一条路线,但感谢您的所有回答!
最佳答案
我的信封也有类似的问题,我对此进行了修复。我将使用您提供的数据发布修复程序,您必须检查一切是否正常:
用于编辑请求的自定义类:
class CustomSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version) {
$request = str_replace('<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">', '', $request);
// parent call
return parent::__doRequest($request, $location, $action, $version);
}
}
设置 SOAP 客户端:
$client = new CustomSoapClient($wsdl,
array(
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'exceptions' => true,
'trace' => 1,
'soap_version' => SOAP_1_2,
)
);
请求:
//notice that the envelope is in the request! also you need to change the urn
$request = '
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/xmlns:ns1="urn:[taken out for security purposes]">
<soap:Body>
<SendPurchases xmlns="urn:...">
</SendPurchases>
</soap:Body>
</SOAP-ENV:Envelope>';
$xmlvar = new SoapVar($request, XSD_ANYXML);
$result = $client->Controleer($xmlvar);
print_r($result); // finally check the result
希望这对你有帮助:)
关于php - SOAP 设置正确的 xmlns header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17114545/