首页 > 解决方案 > 如何在 PHP 中为 SOAP 客户端正确设置 Cookie/Header?

问题描述

我正在尝试根据我在那里找到的几个主题启用对 SOAP 调用的 xDebug 支持(请参阅本文末尾的列表),这就是我到目前为止所做的:

$this->_client_soap = new SoapClient(
    $this->ecase_wsdl,
    array(
        'trace'        => 1,
        'exceptions'   => true,
        'soap_version' => SOAP_1_1,
        'cache_wsdl'   => WSDL_CACHE_NONE
    )
);

// Xdebug Support
$xdebug_remote_address = $this->CI->config->item('xdebug_remote_address');
$xdebug_cookie         = $this->CI->config->item('xdebug_cookie');

if ($xdebug_remote_address && $xdebug_cookie) {
    $this->_client_soap->setCookie('X-Xdebug-Remote-Address', $xdebug_remote_address);
    $this->_client_soap->setCookie('Cookie', $xdebug_cookie);
}

$soap_string = $this->build_add_new_case_xml_string();

$ecase_response = $this->_client_soap->__doRequest(
    $soap_string,
    $this->ecase_wsdl,
    $this->service,
    SOAP_1_1
);

但我收到以下SoapFault错误消息:

Function ("setCookie") is not a valid method for this service

我在这里缺少什么?设置 Cookie/Header 的正确方法是什么?我的 PHP 版本是 5.3.3

之前检查的文章:

标签: phpsoapsoap-clientphp-5.3

解决方案


http://php.net/manual/en/soapclient.setcookie.php

但是看到函数被定义为魔法,你不应该直接调用它。

小心。


推荐阅读