【问题标题】:SoapServer sends text/html header instead of text/xmlSoapServer 发送 text/html 标头而不是 text/xml
【发布时间】:2012-04-03 23:24:27
【问题描述】:

我的肥皂服务器在响应标头中发送 Content-Type: text/html。我需要内容类型:text/xml。

public function index()
{
    $this->layout = 'soap';
    ini_set("soap.wsdl_cache_enabled", "0");
    $this->server = new SoapServer('wsdl/tur.wsdl', array(
            'soap_version' => SOAP_1_2, 
    ));
    $this->server->setObject($this);
    $this->server->handle();
}

这是服务器的响应:

HTTP/1.1 200 正常
日期:格林威治标准时间 2012 年 3 月 19 日星期一 12:17:10
服务器:Apache/2.2.20 (Ubuntu)
X-Powered-By:PHP/5.3.6-13ubuntu3.6
设置 Cookie:CAKEPHP=msmid2fijgrj1efjs0otl8qfj1;过期=格林威治标准时间 2012 年 3 月 19 日星期一 16:17:10;路径=/
P3P:CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
变化:接受编码
内容编码:gzip
内容长度:877
内容类型:text/html;字符集=UTF-8

我尝试使用 text/xml 内容类型调用 header()

public function index()
{
    $this->layout = 'soap';
    ini_set("soap.wsdl_cache_enabled", "0");

    header("Content-Type: text/xml");

    $this->server = new SoapServer('wsdl/tur.wsdl', array(
        'soap_version' => SOAP_1_2, 
    ));
    $this->server->setObject($this);
    $this->server->handle();
}

构建SoapServer前后,但没有结果。

【问题讨论】:

  • 从未使用过此功能,但在文档中有 SoapServer::addSoapHeader 您是否尝试过覆盖 Content-Type?
  • 根据handle 文档上的评论,“...SoapServer::handle(); 方法向浏览器发送额外的 HTTP 标头。其中之一是 'Content-Type: application/soap+xml ’。”不是真正的答案,但可能会提供一些见解。

标签: php soapserver


【解决方案1】:

(在问题编辑中回答。转换为社区 wiki 答案。见Question with no answers, but issue solved in the comments (or extended in chat)

OP 写道:

已解决,这是一个 сakephp 功能。感谢How to write content type in cakephp?

public function index()
{
    $this->layout = 'soap';
    ini_set("soap.wsdl_cache_enabled", "0");
    $this->server = new SoapServer('wsdl/tur.wsdl', array(
        'soap_version' => SOAP_1_2,
    ));
    $this->server->setObject($this);
    $this->server->handle();

    $this->RequestHandler->respondAs('text/xml');
}

【讨论】:

    猜你喜欢
    • 2022-10-14
    • 1970-01-01
    • 2016-03-10
    • 2021-08-04
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    相关资源
    最近更新 更多