如何更改默认soap报头


How to change the default soap header?

我使用这个代码来设置标题。

$root = new 'SimpleXMLElement('<S:Header/>');

,我得到这个错误。

SimpleXMLElement::__construct():命名空间错误:命名空间前缀S未定义。

有人知道怎么解决这个问题吗?:/提前感谢:)

您需要为前缀s定义名称空间

$root = new SimpleXMLElement('<S:Header></S:Header>', LIBXML_NOERROR, false, 'S', true);
//add namespace attribute into root element
$root->addAttribute('xmlns:xmlns:S','mynamespace');
print_r($root->asXML());