【问题标题】:Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers致命错误:未捕获的 SoapFault 异常:[HTTP] 获取 http 标头时出错
【发布时间】:2013-01-07 08:44:38
【问题描述】:

我正在尝试使用 XML 输出“Hello World”,但在我的 php 页面中出现以下异常:

致命错误:未捕获的 SoapFault 异常:[HTTP] Error Fetching http headers in C:\wamp\www\Web_Service\SampleXML\index.php:4 堆栈跟踪:
#0 [内部函数]: SoapClient->_doRequest(' #1【内部函数】:SoapClient->_call('getHelloWorld', Array)
#2 C:\wamp\www\Web_Service\SampleXML\index.php(4): SoapClient->getHelloWorld()
#3 {main} 在第 4 行的 C:\wamp\www\Web_Service\SampleXML\index.php 中抛出

index.php

<?php
    $client = new SoapClient('service.wsdl');
    $response = $client->getHelloWorld(); 
    echo $response;
?>

service.wsld

<?xml version = '1.0' encoding = 'UTF-8' ?>

<definitions name = "Web Service"
    targetNamespace = 'http://example.org/service'
    xmlns:tns = 'http://example.org/service'
    xmlns:soap = 'http://schemas.xmlsoap.org/wsdl/soap/'
    xmlns:xsd = 'http://www.w3.org/2001/XMLSchema'
    xmlns:soapenc = 'http://schemas.xmlsoap.org/soap/encoding/'
    xmlns:wsdl = 'http://schemas.xmlsoap.org/wsdl/'
    xmlns = 'http://schemas.xmlsoap.org/wsdl/' >

    <!-- Message -->
    <message name='getHelloWorld'>
        <part name='response' type='xsd:string' />
    </message>

    <!-- Operations offered -->
    <portType name = 'PortType'>
        <operation name = 'getHelloWorld'>
                <!-- Target Name Space -->
                <output message = 'tns:getHelloWorld' />
        </operation>
    </portType>

    <!-- Binding Element -->
    <binding name = 'Binding' type = 'tns:PortType'>
        <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
        <operation name='getHelloWorld'>
            <soap:operation soapAction = 'urn:localhost-service#getHelloWorld' />

        <!-- Output -->
        <output>
            <soap:body use='encoded' namespace='urn:locahost-service' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
        </output>
        </operation>
    </binding>

    <!-- Define the service -->
    <service name='Service'>
        <port name='Port' binding='Binding' >
            <!-- Location -->
            <soap:address location='http://localhost/Web_Service/SampleXML/soap-server.php' />
        </port>
    </service>

</definitions>

soap-server.php

<?php

    function getHelloWorld() {
        return "Hello World";
    }

    ini_set("soap.wsdl_cache_enabled", "0");

    $server = new SoapServer('service.wsdl');
    $server->addFunction("getHelloWorld");    
    $server->handle();

?>

我是否遗漏了代码中的某些内容?

【问题讨论】:

  • 如果直接调用soap-server.php有什么错误吗?
  • 没有错误。只是一个空白页。
  • 当您查看源代码时,您会看到任何输出吗?
  • 源代码没有输出。
  • 也许你的soapserver没有被初始化,添加一些异常处理或简单检查它是否正在创建?

标签: xml fatal-error php soapfault


【解决方案1】:

尝试设置这条线,

ini_set("default_socket_timeout", 200);

或者把它放在 php.ini 中

 default_socket_timeout = 200

【讨论】:

    【解决方案2】:

    我想为时已晚,但我也有同样的问题。我尝试了套接字超时,但它不起作用。 我的问题是客户端和服务器在同一个物理服务器中。客户端代码在同一个物理服务器上工作时,我收到此错误,但是,将相同的客户端代码移动到我的本地主机,请求服务器,(客户端和服务器在两个不同的机器中执行)一切正常。

    也许这可以帮助别人!

    【讨论】:

      【解决方案3】:

      我在密集的 SOAP 调用中遇到了这个问题,解决方案在 apache 的 httpd.conf 中关闭 KeepAlive。

      将 KeepAlive Off 添加到 httpd.conf 并重新启动 apache。

      【讨论】:

        【解决方案4】:

        我只是想报告这个错误是在你尝试连接到服务器时触发的,而该服务器回复无效数据或根本不回复。

        增加超时可能会有所帮助,但仅在服务器响应时间过长的情况下,如前所述,您可以增加 php.ini 中的值

        default_socket_timeout = 200

        【讨论】:

        • 虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。请阅读此how-to-answer 以提供高质量的答案。
        猜你喜欢
        • 2010-10-29
        • 2011-06-17
        • 1970-01-01
        • 2012-02-18
        • 1970-01-01
        • 2012-12-19
        • 1970-01-01
        • 2018-07-07
        • 2015-10-15
        相关资源
        最近更新 更多